I have a list of column names & want to drop the rows that have more than 1 NaN
values but this error occurs: dropna() got an unexpected keyword argument 'thresh'
.
My pandas is updated, the version is 1.1.5
Previously I’ve done a little data cleaning, think it caused my df rows to become str, but I converted them to np.nan
…
My Whole Code:
df = pd.read_csv('dataframe.csv', index=False) col_list = ['col1', 'col2', 'col3'] """ # DataClean for col in col_list: df[col] = pd.to_numeric(df[col] .str.replace('[^0-9- ]', '') .str.split(' - ') .explode() ).mean(level=0) """ df = df.replace('NaN', np.nan) for col in col_list: df[col] = df[col].dropna(thresh=1, axis=0)
Advertisement
Answer
When you use dropna(thresh=1, axis=0)
it will drop rows that have just nan
values, for your purpose, you can do the following:
df.dropna(subset=col_list, how='any', axis=0)