Pandas
分组计算
groupby用法
df.type1.value_counts()
grouped=df.groupby('type1')
grouped.size()
grouped.groups
len(grouped)
统计计算
grouped.sum()
grouped.mean()
grouped['against_bug'].std()
import numpy as np
grouped.agg([np.mean,np.sum,np.std])
grouped.agg({
'against_bug':np.mean,'against_dark':np.sum,'against_dragon':np.std})
表的组合
pd.concat([df1,df2,df3])
函数merge()一次只能组合两张表
pd.merge(df1,df2,on=['C','D'])
pd.merge(df1,df3,how='left',on=['C','D'])
pd.merge(df1,df3,how='outer',on=['C','D'])
df1.set_index(['C','D']