我有一个像这样的数据框:
desc id info
[a,b,c] 2 type
[u,v,w] 18 tail
三列:desc、id、info,desc 是一个列表。我想要这个:
des id info
a 2 type
b 2 type
c 2 type
u 18 tail
v 18 tail
w 18 tail
这意味着将列表列分解为多行,其他列没有变化。
我真的不知道该怎么做...
这是一种方法
df.set_index(['id', 'info']).desc.apply(pd.Series).stack()\
.reset_index(name = 'desc').drop('level_2', axis = 1)
id info desc
0 2 type a
1 2 type b
2 2 type c
3 18 tail u
4 18 tail v
5 18 tail w
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)