如何在pandas上按键转置数据帧组?

2024-10-16 22:33:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我的数据库中有这个表,我需要一个按调查id的转置组

id  answer  survey_id   question_number questionid 
216     0.0         69               3         2.0   
217     3.0         69               4         3.0   
218     0.0         69               5         4.0   
219     0.0         69               6         5.0   
221     0.0         69               8         7.0 

像这样:

Survey P01  P02 P03 P04 P05
69     1    1   2   2   1

单元格是答案,列的格式是“p{question\u number}”

我用的是熊猫0.18.1。

我该怎么做?


Tags: 答案answerid数据库number格式surveyquestion