Skip to content
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

Add example for pandas in README #84

Closed
mikel-brostrom opened this issue Jul 3, 2023 · 5 comments
Closed

Add example for pandas in README #84

mikel-brostrom opened this issue Jul 3, 2023 · 5 comments
Labels
Information This issue is mostly informative

Comments

@mikel-brostrom
Copy link

mikel-brostrom commented Jul 3, 2023

I just used your library with pandas, but I could not find a single example on how to do this, so I though it would be nice to leave one here. I applied an IntervalDict on a column:

intervals = IntervalDict(
    {
        popen(    -inf,    5):   lambda y:  0,
        pclosedopen( 5,    8.6): lambda y: -0.1 * y + 10, 
        pclosedopen( 8.6, 18):   lambda y: -0.1 * y + 4.39,
        pclosedopen(18,   25):   lambda y: -0.2 * y + 3,
        pclosedopen(25,  inf):   lambda y:  0.8
    }
)
df['Y_interval'] = df['Y'].apply(lambda y: intervals[y](y))
@mikel-brostrom mikel-brostrom changed the title Add exanmples for pandas in README Add example for pandas in README Jul 3, 2023
@AlexandreDecan
Copy link
Owner

Hello,

Thanks for this. But could you clarify the purpose and context of this piece of code? I don't see exactly which problem it addresses.

@AlexandreDecan AlexandreDecan added the Information This issue is mostly informative label Jul 4, 2023
@mikel-brostrom
Copy link
Author

mikel-brostrom commented Jul 5, 2023

It is just an example on how to apply an interval dict on a pandas dataframe column. Nothing more

@AlexandreDecan
Copy link
Owner

Ok, so a kind of value-based map function that, depending on the value, apply a different function on a column. Right? To some extent, the goal of this example is to show how to apply different functions without having to rely on combinations of "where"?

@mikel-brostrom
Copy link
Author

Ok, so a kind of value-based map function that, depending on the value, apply a different function on a column.

Exactly

@AlexandreDecan
Copy link
Owner

Ok, thanks ! Let's keep the "information" label for this issue, and I'll refer to it in a (not yet created) "recipe" section of the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Information This issue is mostly informative
Projects
None yet
Development

No branches or pull requests

2 participants