-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH: add errors='raise' option to rename #13473
Comments
I suspect it is intentional. Either way, the behavior should be clarified in the docs. Missing keys (in columns but not in the dict) are explicitly documented. I know I've used this in the past. For example a bunch of CSVs with variations on the same items. I'll make one dictionary with all the mappings renamer = {'zip': 'zip_code', 'postal code': 'zip_code', ...}` And use that same |
OK. You know this better than me - do you think this is too much vs the increase in explicitness? df.rename(columns={col: renamer[col] for col in renamer if col in df.columns}) |
For
We could maybe add this to rename as well to have similar functionality? (although the default value would be different for rename) |
Having a keyword to control this would be great. Another option is to revisit the "tell people to use
|
Is there a particular reason why the default value would be "ignore" for |
Historical reasons. I think raising would be preferable though correct would require deprecation cycle |
To be clear, I don't think there's a consensus for deprecating the current behavior. Just adding the option to raise when not present. |
This issue is closed but the problem still persists. |
@bala-analytics the original example correctly raises with |
Is there a reason that
.rename
doesn't raise if keys are supplied that don't exist? This caught me out a couple of times:The text was updated successfully, but these errors were encountered: