search

Home  >  Q&A  >  body text

Python dataframe中如何使y列按x列进行统计?


如图:busy=0 or 1,求出busy=1时los的平均,同样对busy=0时也求出los的平均

高洛峰高洛峰2787 days ago592

reply all(1)I'll reply

  • ringa_lee

    ringa_lee2017-04-18 10:34:11

    First groupie, then mean:

    import pandas as pd
    df = pd.DataFrame({'busy': [1, 0, 0],
                      'los': [0.8111, 1.1011, 0.912]})
    df.groupby('busy').mean()

    reply
    0
  • Cancelreply