Skip to content

Instantly share code, notes, and snippets.

@msure
Created December 1, 2017 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msure/3c68d68d0f3bf9b2de087539bdc8baf5 to your computer and use it in GitHub Desktop.
Save msure/3c68d68d0f3bf9b2de087539bdc8baf5 to your computer and use it in GitHub Desktop.
Example of Dplyr Code From R Reproduced In Python's Pandas
# https://www.reddit.com/r/datascience/comments/7ggdlz/what_do_you_hate_about_pandas/dqj6kaw/
# some_df %>%
# mutate(new_column = do_something(old_column)) %>%
# group_by(new_column) %>%
# summarize(some_means = mean(other_column))
df.assign(new_column = do_something(lambda x: x.old_column)) \
.groupby('new_column') \
.agg({'other_column':'mean'})
.rename(columns={'mean':'some_means'})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment