I have a dataframe like this:
desc id info
[a,b,c] 2 type
[u,v,w] 18 tail
Three columns: desc,id,info and desc is a list.I want this:
des id info
a 2 type
b 2 type
c 2 type
u 18 tail
v 18 tail
w 18 tail
That means exploded the list column into multiple rows and other column no changes.
I really don't know how to do this...
解决方案
Here is one way
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