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

ply_select doesn't work for grouped mutate #9

Open
jkeirstead opened this issue Jul 29, 2016 · 0 comments
Open

ply_select doesn't work for grouped mutate #9

jkeirstead opened this issue Jul 29, 2016 · 0 comments

Comments

@jkeirstead
Copy link

With dplyr, I often find myself using mutate to calculate a item-level value using a grouped aggregate. For example:

flights %>%
  group_by(year) %>%
  mutate(mean_delay = mean(arr_delay),
         std_delay = sd(arr_delay),
         z_delay = (arr_delay - mean_delay)/std_delay)

From the docs, I thought that the first step of the pandas-ply equivalent would be:

(flights
  .groupby('year')
  .ply_select('*',
    mean_delay = X.arr_delay.mean(),
    std_delay = X.arr_delay.std())
)

But when I try this I get the following error:

Traceback (most recent call last):
  File "<pyshell#17>", line 5, in <module>
    sd = X.arr_delay.std()))
TypeError: _ply_select_for_groups() takes exactly 1 argument (4 given)

The problem appears to be the '*' argument not working when ply_select operates on a group.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant