I hope you are doing well. I have a pandas data frame with a column containing with the following patterns "Region/Country/City". I need to create 3 new columns: Region, Country and City assigning its corresponding values. I appreciate your support and collaboration on guidance to solve this.
Many thanks Hernan
You can use pd.Series.str.split('/', expand=True)
ex:
a = pd.DataFrame({
'data': ['Region/Country/City']
})
a[['region', 'country', 'city']] = a['data'].str.split('/', expand=True)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.