Python 当一个单元格的列具有多个值时,将数据帧行拆分为多行
我有以下数据帧:Python 当一个单元格的列具有多个值时,将数据帧行拆分为多行,python,pandas,Python,Pandas,我有以下数据帧: df = pd.DataFrame({'idtag': {0: "12,43,65", 1: "12,55,15", 2:"23"}, '# of Boxes': {0: 1, 1: 2, 2:2}, }, columns=['idtag', '# of Boxes', ]) df.head() idtag # of Boxes 0 12,43,65 1 1 12,
df = pd.DataFrame({'idtag': {0: "12,43,65", 1: "12,55,15", 2:"23"},
'# of Boxes': {0: 1, 1: 2, 2:2},
},
columns=['idtag', '# of Boxes', ])
df.head()
idtag # of Boxes
0 12,43,65 1
1 12,55 2
2 23 2
我想按其idtag拆分每一行,以便最终产品如下所示:
idtag # of Boxes
0 12 1
1 43 1
2 65 1
3 12 2
4 55 2
5 23 2
我尝试将IDTag拆分为列表并对其进行迭代,但我无法理解
谢谢 绝对正确,回答了这个问题绝对正确,回答了这个问题