Applying function to pandas series receives series instead of row with swifter
See original GitHub issue `def split_fk_keys(desc):
desc_split = desc.split('_')
if len(desc_split) > 1:
return "{}{}".format(desc_split[0], "Key")
else:
return desc`
This one works in plain pandas:
`relations['column_name'].apply(split_fk_keys)`
This one doesn’t work with swifter, relations[‘column_name’] returns a Series, and that series is passed as argument to the split_fk_keys method instead of each row in that series:
`relations['column_name'].swifter.apply(split_fk_keys)`
Same problem when tried it this way (should make no difference as it’s actually same as above):
`relations['column_name'].swifter.apply(lambda row: split_fk_keys(row))`
Or even:
`relations.swifter.apply(lambda row: split_fk_keys(row['column_name']))`
Issue Analytics
- State:
- Created 2 years ago
- Reactions:7
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Swifter — automatically efficient pandas apply operations
An introduction to swiftapply, a generalized method for easily and efficiently applying any function to a pandas dataframe or series.
Read more >12 Ways to Apply a Function to Each Row in a DataFrame
Pandas DataFrame apply function (df.apply) is quite versatile and is a popular choice. To make it process the rows, you have to pass...
Read more >swifter/documentation.md at master · jmcarpenter2 ... - GitHub
Efficiently apply any function to a pandas series in the fastest available manner ... True : the passed function will receive ndarray objects...
Read more >Do You Use Apply in Pandas? There is a 600x Faster Way.
The fastest way to work with Pandas and Numpy is to vectorize your functions. On the other hand, running functions element by element...
Read more >Applying a row-wise function to a Pandas dataframe
A function is applied to each row, taking the row elements as input, either as distinct scalar arguments, as an array, or as...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ll test it in my spare time, currently the project is working using plain pandas without swifter. Nice to see there is progression on this issue, good work! 😃
Didn’t mean to close it. Was hoping to get some feedback from the folks here first. Version
1.1.3
is now available! Please try and let me know 😃