I have a pandas DataFrame with one column, say:
df = pd.DataFrame({"combined_list": [["Netherlands|NL", "Germany|DE", "United_States|US", "Poland|PL"], ["Netherlands|NL", "Austria|AU", "Belgium|BE"], ["United_States|US", "Germany|DE"]]})
I want to create two columns from the combined_list column:
- One containing al the normal country names (So everything before the last occurence of
|) - One column containing all 2 letter abbreviations (The length of these is always 2) , so basically all remaining text after the last occurence of
|
The resulting Dataframe should look like this:
countries abbreviations
[Netherlands, Germany, United_States, Poland] [NL, DE, US, PL]
[Netherlands, Austria, Belgium] [NL, AU, BE]
[United_States, Germany] [US, DE]
How to achieve this?
I know if the column of the Dataframe would simply be one string, I could use various string split functions to achieve it, but can't find anything for columns of lists