Pandas How to filter a Series

后端 未结 7 1891
自闭症患者
自闭症患者 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:35

    If you like a chained operation, you can also use compress function:

    test = pd.Series({
    383:    3.000000,
    663:    1.000000,
    726:    1.000000,
    737:    9.000000,
    833:    8.166667
    })
    
    test.compress(lambda x: x != 1)
    
    # 383    3.000000
    # 737    9.000000
    # 833    8.166667
    # dtype: float64
    

提交回复
热议问题