question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 2 years ago
  • Reactions:7
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
dablacommented, Apr 13, 2022

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! 😃

1reaction
jmcarpenter2commented, Apr 13, 2022

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 😃

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found