kieferk / dfply

dplyr-style piping operations for pandas dataframes
GNU General Public License v3.0
889 stars 103 forks source link

Add mutate_if() function and test cases #23

Closed bleearmstrong closed 6 years ago

bleearmstrong commented 7 years ago

Adds mutate_if() function. This might be a good place to add some helper functions that can represent common use cases that don't appear to be part of pandas, e.g. an 'is_numeric' function, 'is_character', etc.

Line 103 copies the dataframe, because the function calls an inplace operation. I wasn't sure if that was required or not. If not required, it should probably be removed.

kieferk commented 6 years ago

Added this manually to v0.3.1 due to conflicts with new code.

Apparently pandas now has a bunch of type inference functions in the api:

https://pandas.pydata.org/pandas-docs/stable/api.html#data-types-related-functionality

But I think this was introduced after v0.20 of pandas. I could bump up the requirement for pandas from i think 0.18 that i have it at now, then just create symbolic function versions of these inference methods. Or I could do it manually, but the pandas api functions are certainly going to be more reliable for that.

I'll think about it. I don't really see any issue bumping up the pandas requirement, but it might be annoying for some people.