简体   繁体   English

大熊猫数据框python中的解包列表

[英]unpack list in pandas dataframe python

I have a dataframe having column a,b,c.我有一个包含 a、b、c 列的数据框。 And column c has data in list datatype.并且 c 列具有列表数据类型中的数据。 So I want to unwind/unpacked/explode the each element of list as new row.所以我想将列表的每个元素展开/解压/分解为新行。

so, our input is like below.所以,我们的输入如下。

   a  b             c
0  1  2          [1, {'k': 1}, 2]
1  3  2          [{'m': 2}, {'k': 2}, 2]

And our output should be like below.我们的输出应该如下所示。

   a  b          c
0  1  2          1
1  1  2          {'k': 1}
2  1  2          2
3  3  2          {'m': 2}
4  3  2          {'k': 2}
5  3  2          2

Sp, as you can in output, each element of list is in row and other column a and b values are repeating corresponding to list element Sp,正如您可以在输出中一样,列表的每个元素都在行中,其他列 a 和 b 值重复对应于列表元素

The solutions from the questions linked in the comments are outdated.评论中链接的问题的解决方案已过时。 These days you can just:这些天你可以:

df.explode('c')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM