I am new to Python and am having problems. I have the following data framework:
import pandas as pd
data = {'v1':('Belgium[country]', 'Antwerp[city]', 'Gent[city]', 'France[country]', 'Paris[city]', 'Marseille[city]', 'Toulouse[city]', 'Spain[country]', 'Madrid[city]')}
df = pd.DataFrame(data)
df
v1
0 Belgium[country]
1 Antwerp[city]
2 Gent[city]
3 France[country]
4 Paris[city]
5 Marseille[city]
6 Toulouse[city]
7 Spain[country]
8 Madrid[city]
What I want to display in the following format:
v1 v2
0 Belgium[country] Antwerp[city]
1 Belgium[country] Gent[city]
2 France[country] Paris[city]
3 France[country] Marseille[city]
4 France[country] Toulouse[city]
5 Spain[country] Madrid[city]
I have found a way to do this with a dictionary, but since I want to maintain order, I am looking for a way to do this using a list or so.
I tried this both on the basis of the indices and on the values themselves (in particular [country] and [city]), but I could not cope with them. Any help is much appreciated!
source
share