I have a pandas dataframe looks like as below:
date     |    location          | occurance <br>
------------------------------------------------------
somedate |united_kingdom_london | 5  
somedate |united_state_newyork  | 5   
I want it to transform into
date     | country        | city    | occurance <br>
---------------------------------------------------
somedate | united kingdom | london  | 5  
---------------------------------------------------
somedate | united state   | newyork | 5     
I am new to Python and after some research I have written following code, but seems to unable to extract country and city:
df.location= df.location.replace({'-': ' '}, regex=True)
df.location= df.location.replace({'_': ' '}, regex=True)
temp_location = df['location'].str.split(' ').tolist() 
location_data = pd.DataFrame(temp_location, columns=['country', 'city'])
I appreciate your response.


