groupby
import pandas as pd
import numpy as np
%matplotlib inline
salaries = pd.DataFrame({
'Name': ['July', 'Zewei', 'Zewei', 'Han', 'July', 'July', 'Zewei', 'July'],
'Year': [2016,2016,2016,2016,2017,2017,2017,2017],
'Salary': [10000,2000,4000,5000,18000,25000,3000,4000],
'Bonus': [3000,1000,1000,1200,4000,2300,500,1000]
})
print(salaries)
group_by_name = salaries.groupby('Name')
groupby之后的组,可以做一些sum,mean操作
groupby可以按着多个列分组
group_by_name_list = salaries.groupby(['Name','list'])
选择分组
group_by_name_list.getgroup('Han')
分组后,对每一列操作
zscore = lambda x: (x-x.mean())/x.std()
transformed = nvda.groupby(key).transform(zscore)