Created
December 1, 2017 17:32
-
-
Save msure/3c68d68d0f3bf9b2de087539bdc8baf5 to your computer and use it in GitHub Desktop.
Example of Dplyr Code From R Reproduced In Python's Pandas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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