Reputation: 1019
I have a variety of values in one of my columns in my pandas dataframe. Those include LIMITED LIABILITY CORP, CORPORATION, LIMITED LIABILITY PARTNER, Limited Liability Corporation
All I am trying to do is rename some of the values that are equivalent but are called differently. So here I want to rename Limited Liability Corporation as LIMITED LIABILITY CORP and same thing with the Partnership.
This is the code I have written using map:
Leads_updated['Business_Type'] =
Leads_updated['Business_Type'].map({'Limited Liability Corporation':
'LIMITED LIABILITY CORP', 'Limited Liability Partnership':'LIMITED LIABILITY
PARTNER'})
Now, it does properly change the values that I wanted to change, however, there are other values that I did not change in my code such as "Corporation" that are now gone from my pandas dataframe column.
Why is that and how can I fix it? Thank you!
Upvotes: 0
Views: 269
Reputation: 51395
That is the expected behavior for map
. It sounds like you're looking for replace
instead, which will leave values unchanged if it is not in your dictionary keys:
Leads_updated['Business_Type'].replace({'Limited Liability Corporation': 'LIMITED LIABILITY CORP', 'Limited Liability Partnership':'LIMITED LIABILITY PARTNER'})
Upvotes: 1