I have a df with two columns col1
and col2
. I'm trying to split if there is any comma seperated values.
For ex: From 1,2 - mason
to 1 - mason
and 2 - mason
df
df= pd.DataFrame(data = {'col1' : ['1,2', '2', '3', '4', '5,6,7,8'], 'col2' : ['mason', 'marcus', 'anthony', 'paul', 'bruno']})
col1 col2
0 1,2 mason
1 2 marcus
2 3 anthony
3 4 paul
4 5,6,7,8 bruno
My excepted output:
col1 col2
0 1 mason
1 2 mason
2 2 marcus
3 3 anthony
4 4 paul
5 5 bruno
6 6 bruno
7 7 bruno
8 8 bruno
9 9 bruno