I am reading data from a csv file into a pandas dataframe. Now some of the rows contain data in only one column (can be any column) and rest columns are NaN. The actual data may also contain some NaNs, therefore I want to drop all such rows where exactly one column contains data and rest are NaNs.
Therefore neither df = df.dropna(how='all')
nor df = df.dropna(how='any')
solves my issue.
Sample dataframe:
1 2 3 ... 19 20
text NaN NaN ... NaN NaN
NaN abc NaN ... NaN NaN
NaN NaN xyz ... NaN NaN
a b c ... NaN z
.
.
What I want become:
1 2 3 ... 19 20
a b c ... NaN z
.
.
question from:
https://stackoverflow.com/questions/65919332/pandas-drop-rows-where-all-but-one-column-is-nan 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…