Ad

TypeError: Dropna() Got Multiple Values For Argument 'axis'

- 1 answer

I am trying to drop a list of columns that are in df

cols = df.columns[df.isna().any()].tolist()
df = df.dropna([cols], axis = 1)

But I get the error

TypeError: dropna() got multiple values for argument 'axis'

Any ideas how I can drop the list in cols ?

Ad

Answer

I think need boolean indexing with loc:

df1 = df.loc[:, df.notna().all()]
#alternative with iverting mask by ~
#df1 = df.loc[:, ~df.isna().any()]
#alternative 1
#df1 = df.dropna(axis=1)

For your solution need drop with omit list [] for remove columns:

cols = df.columns[df.isna().any()]
df1 = df.drop(cols, axis = 1)
print (df1)
Ad
source: stackoverflow.com
Ad