I have a pandas dataframe and for one of my columns, I need to combine some of the values however I'm not sure what function to use (merge, sum, concatenate, etc.) I have a dataframe with 5 columns (postal code, borough, neighbourhood, latitude, longitude) and for the borough column, there are 10 unique boroughs however I need it to be 6 boroughs only, therefore I need to combine 4 of the boroughs(East Toronto, Downtown Toronto, West Toronto and Central Toronto)enter image description here into one borough and name this borough Old Toronto. How do I do this without losing all the neighbourhoods in the boroughs which I need to combine?
Replace them like below:
l=['East Toronto', 'Downtown Toronto', 'West Toronto', 'Central Toronto'] df['borough']=df['borough'].str.replace('|'.join(l),"Old Toronto")
2.1m questions
2.1m answers
60 comments
57.0k users