0

I got a excel file which contains the following,

Name  id   
A     123
B     124,125,126   
C     127

After calling pandas.read_excel() to create the dataframe, I noticed that 124,125,126 was taken as str. And others were int.

I would like to know pythonic way to convert this into a list, without writing a loop.

Name  id   
A     123
B     [124,125,126]  
C     127

So that I can expand the dataframe in the below format, which was mentioned here, Expand pandas DataFrame column into multiple rows

Name    id
A       123
B       124
B       125
B       126
C       127

Many thanks in advance.

1 Answers1

0
s = "124,125,126"
[int(x) for x in s.split(",")]