I have a df like this
x y1 y2 y3 y4
0 -20.0 NaN NaN NaN NaN
1 -19.9 NaN NaN 20 NaN
2 -19.8 NaN NaN NaN NaN
3 -19.7 NaN NaN NaN NaN
4 -19.6 NaN 10 NaN NaN
I want the program to drop all rows with only NaN values in columns y1 to y4.
The output would be this:
x y1 y2 y3 y4
1 -19.9 NaN NaN 20 NaN
4 -19.6 NaN 10 NaN NaN
I tried df.dropna(axis = 0, how = "all", inplace = True) but this counts column x aswell.
CodePudding user response:
You need to specify your columns as subset:
df.dropna(subset=['y1', 'y2', 'y3', 'y4'], how='all', inplace=True)
Output:
x y1 y2 y3 y4
1 -19.9 NaN NaN 20.0 NaN
4 -19.6 NaN 10.0 NaN NaN
