Pandas - Delete Rows with only NaN values

前端 未结 2 1025
日久生厌
日久生厌 2021-02-05 13:54

I have a DataFrame containing many NaN values. I want to delete rows that contain too many NaN values; specifically: 7 or more.

I tried using the dr

2条回答
  •  天命终不由人
    2021-02-05 14:08

    Basically the way to do this is determine the number of cols, set the minimum number of non-nan values and drop the rows that don't meet this criteria:

    df.dropna(thresh=(len(df) - 7))
    

    See the docs

提交回复
热议问题