Pandas best way to subset a dataframe inplace, using a mask

前端 未结 2 1663
渐次进展
渐次进展 2021-01-02 11:31

I have a pandas dataset that I want to downsize (remove all values under x).

The mask is df[my_column] > 50

I would typically just use

相关标签:
2条回答
  • 2021-01-02 11:59

    I think this works. Maybe there are better ways?

    df = df.drop(df[df.my_column < 50].index)

    0 讨论(0)
  • 2021-01-02 12:21

    You are missing the inplace parameter :

    df.drop(df[df.my_column < 50].index, inplace = True)

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