At first, I tried writing some code that looked like this:
import numpy as np import pandas as pd np.random.seed(2016) train = pd.DataFrame(np.random.choice([np.nan, 1, 2], size=(10, 3)), columns=['Age', 'SibSp', 'Parch']) complete = train.dropna() complete['AgeGt15'] = complete['Age'] > 15
After getting SettingWithCopyWarning, I tried using.loc:
complete.loc[:, 'AgeGt15'] = complete['Age'] > 15 complete.loc[:, 'WithFamily'] = complete['SibSp'] + complete['Parch'] > 0
However, I still get the same warning. What gives?