Skip to content

PERF: groupby-diff #16706

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

Closed
jreback opened this issue Jun 15, 2017 · 1 comment · Fixed by #45575
Closed

PERF: groupby-diff #16706

jreback opened this issue Jun 15, 2017 · 1 comment · Fixed by #45575
Assignees
Labels
Groupby Performance Memory or execution speed performance
Milestone

Comments

@jreback
Copy link
Contributor

jreback commented Jun 15, 2017

groupby-diff could be written as a single function that operates on the entire frame all at once. This is essentially a python-look. xref to #11296 for groupby-fillna

In [2]: ngroups=100

In [3]: N=10000

In [6]: df = pd.DataFrame({'time': pd.date_range('20170101', periods=100).take(np.random.randint(0, 100, size=N)), 'id': np.random.randint(0, ngroups, size=N)})

By unwrapping we can get a large perf boost

In [7]: %timeit _ = df.groupby('id').time.diff() / pd.Timedelta('1 day')
22.9 ms ± 443 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)

In [9]: %timeit _ = (df.time - df.groupby('id').time.shift()) / pd.Timedelta('1 day')
2.8 ms ± 24.1 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
@jreback jreback added Difficulty Intermediate Groupby Performance Memory or execution speed performance Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Jun 15, 2017
@jreback jreback added this to the Interesting Issues milestone Jun 15, 2017
@jreback jreback modified the milestones: Interesting Issues, Next Major Release Nov 26, 2017
@mroeschke mroeschke removed the Reshaping Concat, Merge/Join, Stack/Unstack, Explode label Jun 12, 2021
@lukemanley
Copy link
Member

take

@jreback jreback modified the milestones: Contributions Welcome, 1.5 Feb 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Groupby Performance Memory or execution speed performance
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants