目的:
把question_id 对应的user_answer转成ABCD
solution
dfa=df.groupby('question_id').nth(0).reset_index()
dfa['flag']='A'
dfb=df.groupby('question_id').nth(1).reset_index()
dfb['flag']='B'
dfc=df.groupby('question_id').nth(2).reset_index()
dfc['flag']='C'
dfd=df.groupby('question_id').nth(3).reset_index()
dfd['flag']='D'
resdf=dfa.append([dfb,dfc,dfd])
resdf.sort_values(by='question_id')
result:
focus:
g.nth(0)
#同
g.first()
g.head(1)
g.last()
g.nth(2)
g.nth(-1)
g.nth(0,dropna='any')
g.B.nth(0,dropna='all')
g.groups
g.get_group(134429)
g.discribe()
g.agg([np.mean,np.sum.np,std])