2.1.4.5.GroupBy

GroupBy的概念

  • 讓table中有相同ID的row可以成組

操作

  1. 產生groupby物件

     import numpy as np
     import pandas as pd
     data = {'Company': ['GooG', 'GooG', 'Att', 'Att'],
        'Person': ['Sam', 'Mike', 'Ray', 'Neil'],
        'Sales': [200, 100, 130, 500]}
     df = pd.DataFrame(data)
     byComp = df.GroupBy('Company')
  2. 對groupby物件使用aggregate function

     byComp.mean()
     byComp.sum()
     byComp.std()
     byComp.count()
     byComp.min()
     byComp.describe()
     byComp.describe().transpose()

Last updated