I have a dataframe like this:
df = pd.DataFrame({'Parent': ['Stay home', "Stay home","Stay home", 'Go outside'],
'Child' : ['Severe weather, heavy rain', "raining", "Windy", 'Sunny, Good weather'], 'Child1' : ['4day forecast', "NaN", "NaN", 'NaN']})
Parent Child Child1
0 Stay home Severe weather, heavy rain 4day forecast
1 Stay home raining NaN
2 Stay home Windy NaN
3 Go outside Sunny, Good weather NaN
I want to split the Child
column where there exists more than one value on a row.
Expected outcome:
Parent Child Child1
0 Stay home Severe weather 4day forecast
1 Stay home heavy rain 4day forecast
2 Stay home raining NaN
3 Stay home Windy NaN
4 Go outside Sunny NaN
5 Go outside Good weather NaN
The Child column
values can be split with the .split (',')
method but how to make the new rows
?
Any ideas?