I have a pandas df (5568, 108) where the column of interest is df.Age, which has some NaNs (303). I want to keep the NaNs but drop some of the outliers. df.drop(df[df.Age<18]) and df.drop(df[df.Age>90]).
I tried
for index, rows in df.iterrows():
if (df.loc[index, 'Age'] > 0.0 & df.loc[index, 'Age'] < 18.0):
df.drop(df.iloc[index])
elif (df.loc[index, 'Age'] > 0.0 & df.loc[index, 'Age'] > 90.0):
df.drop(df.iloc[index])
else:
continue
But this results in
TypeError: unsupported operand type(s) for &: 'float' and 'numpy.float64'
Any thoughts on how I can achieve this?