-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Refactor DataFrame.replace to dispatch on types #5541
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
Comments
What version of pandas are you using? I believe this is fixed in master. On Monday, November 18, 2013, Noah wrote:
Best, |
You are correct. Let me amend the above then to regard simply the documentation of what is clearly a really complicated replace interface. There should at least be examples of the different types of syntax (I couldn't find any anywhere in the docs). |
See also #5338 |
Yes ... the @jreback maybe we should refactor this API a bit. I think
While this does add more names to the namespace, it's less of a strain on the working memory since you can look at some code with this API and say "oh, this is replacement using a [dict, list, etc]" rather than tracing all the way back up the stack to discover that the types weren't what you thought. |
This is a breaking API change, so it may have to wait until 1.0 or whatever the first breaking API release is. |
@cpcloud nice suggestions maybe could do instead use a an object for e.g.
in theory this would also allow to dispatch in a backwards compat way, e.g. the |
Nice. I like the object based idea. Gives time for users to adapt. |
Yes, I approve of some refactoring here! The current method is too powerful for its own good (although the documentation has improved substantially since I filed this ticket). I haven't done any contributions to the project as of yet, but I'm happy to do at least the documentation parts if someone refactors the code into bits that I can understand. On Apr 6, 2014, at 8:33 AM, Phillip Cloud [email protected] wrote:
|
This looks to work correctly on main now and I believe we have tests for this so closing |
I'm having trouble figuring out how DataFrame.replace() is supposed to work. I'm not sure if this is a bug or a documentation issue.
So far, so good, everything makes sense. But I would have expected this to accomplish the same as above:
As you can see, I'm getting alternating "b" and "a". From a quick browse of the source code, it seems that the dictionary-replacement option should result in the same outcome as the following (which gives what I would have expected):
I'm not sure what the to_replace=dict option is supposed to be doing but (at least for pandas v 0.12.0) it isn't doing what I would have expected.
Whether this is a bug or not, the df.replace() method needs better documentation. It's not enough to include a disclaimer that "This method has a lot of options. You are encouraged to experiment and play with this method to gain intuition about how it works."
The text was updated successfully, but these errors were encountered: