1 回答
TA贡献1875条经验 获得超5个赞
首先使用Series.str.split
witg 正则表达式,然后分配回DataFrame.assign
然后使用DataFrame.explode
,我还在最后一步创建了默认的唯一索引:
df1 = (df.assign(Zip = df['Zip'].str.split('[_ ,\.]'))
.explode('Zip')
.reset_index(drop=True))
print (df1)
Date Item_Code Type Zip
0 1/1/2020 A Long 07
1 1/1/2020 A Long 08
2 1/1/2020 A Long 09
3 12/4/2020 B Small AB
4 12/4/2020 B Small CD
5 12/4/2020 B Small EF
6 12/4/2020 B Small GF
7 13/4/2020 A Long 08
8 13/4/2020 A Long 14
9 1/5/2020 A Long NaN
10 21/5/2020 B Small 09
11 21/5/2020 B Small 07
12 21/5/2020 B Small 16
13 22/5/2020 B Small AB
14 22/5/2020 B Small 07
添加回答
举报