0

I have a data set with multiple values for a single column I am trying to separate them using "," as my delimiter.

my data looks like this:

A:            B:           C:
1             A,B,C,D      Square
2             E,F          Triangle
3             G,H,I        Circle

I am trying to process it in such a way as to get these results:

A:           B:           C:
1            A            Square
1            B            Square
1            C            Square
1            D            Square
2            E            Triangle 
2            E            Triangle
3            G            Circle
3            G            Circle
3            I            Circle

Does anyone have any suggestions?

ThePyGuy
  • 17,779
  • 5
  • 18
  • 45
CRB615
  • 3
  • 3

1 Answers1

1

First split the column values using Series.str.split then explode the column:

>>> df.assign(B=df['B'].str.split(',')).explode('B')

   A  B         C
0  1  A    Square
0  1  B    Square
0  1  C    Square
0  1  D    Square
1  2  E  Triangle
1  2  F  Triangle
2  3  G    Circle
2  3  H    Circle
2  3  I    Circle
ThePyGuy
  • 17,779
  • 5
  • 18
  • 45