thresh in dropna for DataFrame in pandas in python

后端 未结 2 833
抹茶落季
抹茶落季 2020-12-03 18:14
df1 = pd.DataFrame(np.arange(15).reshape(5,3))
df1.iloc[:4,1] = np.nan
df1.iloc[:2,2] = np.nan
df1.dropna(thresh=1 ,axis=1)

It seems that no nan va

相关标签:
2条回答
  • 2020-12-03 18:43

    Thresh=1 means that it keeps the columns which atleast contain 1 NON NA-value. Thresh=2 means that it keeps the columns which atleast contain 2 NON NA-value.

    In your case thresh is 1 and all the columns contains atleast 1 NON Na value. Hence no row is deleted.

    0 讨论(0)
  • 2020-12-03 19:06

    thresh=N requires that a column has at least N non-NaNs to survive. In the first example, both columns have at least one non-NaN, so both survive. In the second example, only the last column has at least two non-NaNs, so it survives, but the previous column is dropped.

    Try setting thresh to 4 to get a better sense of what's happening.

    0 讨论(0)
提交回复
热议问题