点击查看【bilibili】
多重索引
df.groupby(by=['city','education']).mean()
多重索引切片方式
df.groupby(by=['city','education']).mean()['北京']
KeyError: '北京'
先将数据框切为series,再对series切片,注意先切第一重索引,再切第二重索引。
df.groupby(by=['city','education']).mean().avg['北京']['硕士']
19.51063829787234
df.groupby(['city','education']).mean().loc['北京','硕士']
companyId 5.579256e+04
positionId 2.188171e+06
bottom 1.440426e+01
top 2.461702e+01
avg 1.951064e+01
Name: (北京, 硕士), dtype: float64
设置多重索引.set_index([索引1,索引2])
df1=df.set_index(['city','education'])
df1
重置索引.reset_index()
df1.reset_index()
