I have a pandas dataframe with one column like this:
| Merged_Cities |
|---|
| New York, Wisconsin, Atlanta |
| Tokyo, Kyoto, Suzuki |
| Paris, Bordeaux, Lyon |
| Mumbai, Delhi, Bangalore |
| London, Manchester, Bermingham |
And I want a new dataframe with the output like this:
| Merged_Cities | Cities |
|---|---|
| New York, Wisconsin, Atlanta | New York |
| New York, Wisconsin, Atlanta | Wisconsin |
| New York, Wisconsin, Atlanta | Atlanta |
| Tokyo, Kyoto, Suzuki | Tokyo |
| Tokyo, Kyoto, Suzuki | Kyoto |
| Tokyo, Kyoto, Suzuki | Suzuki |
| Paris, Bordeaux, Lyon | Paris |
| Paris, Bordeaux, Lyon | Bordeaux |
| Paris, Bordeaux, Lyon | Lyon |
| Mumbai, Delhi, Bangalore | Mumbai |
| Mumbai, Delhi, Bangalore | Delhi |
| Mumbai, Delhi, Bangalore | Bangalore |
| London, Manchester, Bermingham | London |
| London, Manchester, Bermingham | Manchester |
| London, Manchester, Bermingham | Bermingham |
In short I want to split all the cities into different rows while maintaining the 'Merged_Cities' column.
Here's a replicable version of df:
df = pd.DataFrame({'Merged_Cities':['New York, Wisconsin, Atlanta',
'Tokyo, Kyoto, Suzuki',
'Paris, Bordeaux, Lyon',
'Mumbai, Delhi, Bangalore',
'London, Manchester, Bermingham']})