展平嵌套的 pandas 数据框 [英] Flatten nested pandas dataframe
本文介绍了展平嵌套的 pandas 数据框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何展平嵌套的熊猫数据框,如所附图片所示.
I'm wondering how to flatten the nested pandas dataframe as demonstrated in the picture attached.
嵌套属性由数据"字段给定.简而言之:我有一个参与者列表(用"participant_id"表示),他们在不同的时间提交了响应(数据").我需要创建一个宽数据框,每个参与者在每个时间戳处都有一行数据记录("q1","q2",...,摘要")
The nested attribute is given by 'data' field. In short: I have a list of participants (denoted by 'participant_id') and they submitted responses ('data') at different times. I need to create the wide dataframe, where for each participant at each time stamp there is a row of records of their data ('q1', 'q2',...,'summary')
非常感谢!
推荐答案
尝试一下:
pd.concat([df.data.apply(pd.Series), df.drop('data', axis=1)], axis=1)
这篇关于展平嵌套的 pandas 数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文