Pandas How to filter a Series

后端 未结 7 1862
自闭症患者
自闭症患者 2020-11-30 20:51

I have a Series like this after doing groupby(\'name\') and used mean() function on other column

name
383      3.000000
663      1.000000
726      1.000000
7         


        
相关标签:
7条回答
  • 2020-11-30 21:40

    As DACW pointed out, there are method-chaining improvements in pandas 0.18.1 that do what you are looking for very nicely.

    Rather than using .where, you can pass your function to either the .loc indexer or the Series indexer [] and avoid the call to .dropna:

    test = pd.Series({
    383:    3.000000,
    663:    1.000000,
    726:    1.000000,
    737:    9.000000,
    833:    8.166667
    })
    
    test.loc[lambda x : x!=1]
    
    test[lambda x: x!=1]
    

    Similar behavior is supported on the DataFrame and NDFrame classes.

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