I have the following;
mylist = ["name", "state", "name", "city"]
newlist = ["name1", "state", "name2", "city"]
I have renamed the duplicates. I would like to merge the name1
and name2
and rename to name
I have the following;
mylist = ["name", "state", "name", "city"]
newlist = ["name1", "state", "name2", "city"]
I have renamed the duplicates. I would like to merge the name1
and name2
and rename to name
This method works well to do this and is clean:
Renamed DataFrame method accepts the dictionary "key: values" that allow you to map the old value to the new value.
Example.
new_df = "read in data source"
col_map = {"name": "name1",
"state": "state",
"name": "name2",
"city": "city"
}
new_df.rename(columns=col_map)
This method should work perfectly fine. Please respond so that our team here in StackOverflow knows that you care about our feedback and are responsive.