我有一个看起来像以下数据框的groupby对象:
df = pd.DataFrame({'user1':[2,4,21,21],'user2':[6,13,76,76],'param1':[0,2,0,1],'param2':['x','a','a','d'],'count':[1
,3,2,1]}, columns=['user1','user2','param1','param2','count'])
df = df.set_index(['user1','user2','param1','param2'])
给出
count
user1 user2 param1 param2
2 6 0 x 1
4 13 2 a 3
21 76 0 a 2
1 d 1
我想要这样的东西:
param1 0 1 2
param2 a x d a
user1 user2
2 6 0 1 0 0
4 13 0 0 0 3
21 76 2 0 1 0