-1

I have large number of columns in my datasets and there are many columns that have various null values therefore tried to delete all those columns from pandas DataFrame which have null values more than 40. I made a "delete_col" function and used drop() in order to delete those columns but when I run that function got a pathetic error. How to solve this error?

ValueError: Need to specify at least one of 'labels', 'index' or 'columns'

def delete_col(df):
    for i in df.columns:
        if df[i].isna().sum() > 40:
            df[i].drop(inplace=True)
        else:
            pass
delete_col(df)

If someone can solve this error would be great help.

Mohd Aziz
  • 11
  • 2

1 Answers1

0

replace:

df[i].drop(inplace=True)

with:

df.drop(i, inplace=True)
SiP
  • 1,080
  • 3
  • 8