1

I have the following dataframe:

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

I want to split each row by its idtag so that the end product looks like this:

    idtag      # of Boxes
0   12          1
1   43          1
2   65          1
3   12          2
4   55          2
5   23          2

I tried splitting the idtags into lists and iterating over them but I couldn't figure it out.

Thanks!

M Arroyo
  • 445
  • 3
  • 14

0 Answers0