Pandas How to filter a Series

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

    A fast way of doing this is to reconstruct using numpy to slice the underlying arrays. See timings below.

    mask = s.values != 1
    pd.Series(s.values[mask], s.index[mask])
    
    0
    383    3.000000
    737    9.000000
    833    8.166667
    dtype: float64
    

    naive timing

提交回复
热议问题