Skip to content
Advertisement

How to Drop rows in DataFrame by conditions on column values

I created code to drop some rows according to certain condition :

df3 = df_clean[(df_clean['group'] == 'treatment') & (df_clean['landing_page'] != 'new_page')].index
df2 = df_clean.drop(df3 , inplace=True)
df2.head()

but I got this error: AttributeError: ‘NoneType’ object has no attribute ‘head’

Advertisement

Answer

Assign df_clean to df2 without the inplace

 df2 = df_clean.drop(df3)

Or leave the inplace without assigning, here df_clean will be your output

 df_clean.drop(df3 , inplace=True)
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement