【发布时间】:2026-01-08 11:35:02
【问题描述】:
我有如下数据框。我想将列 zip 中的值拆分为行值,如下所示。这些分隔符可以用_ ,. 分隔这些值。这在 python 中是如何实现的。
输入
df.head(5)
Date Item_Code Type Zip
1/1/2020 A Long 07_08_09
12/4/2020 B Small AB_CD_EF_GF
13/4/2020 A Long 08_14
1/5/2020 A Long
21/5/2020 B Small 09,07,16
22/5/2020 B Small AB,07
预期输出
Date Item_Code Type Zip
1/1/2020 A Long 07
1/1/2020 A Long 08
1/1/2020 A Long 09
12/4/2020 B Small AB
12/4/2020 B Small CD
12/4/2020 B Small EF
12/4/2020 B Small GF
13/4/2020 A Long 08
13/4/2020 A Long 14
1/5/2020 A Long
21/5/2020 B Small 09
21/5/2020 B Small 07
21/5/2020 B Small 16
22/5/2020 B Small AB
22/5/2020 B Small 07
【问题讨论】:
标签: python regex python-3.x pandas dataframe