In Python Pandas, I want to add columns by executing multiple aggregate functions on multiple columns like R dplyr mutate_each. For example, Can Python Pandas realize the same processing as the following R script?
R dplyr :
iris %>%
group_by(Species) %>%
mutate_each(funs(min, max, mean), starts_with("Sepal"))
However, I was able to achieve the same processing as mutate with Pandas. As shown in the code below, I could execute one aggregate function and add one column.
R dplyr :
iris %>% group_by(Species) %>% mutate(MaxSepalLen = max(Sepal.Length))
Python Pandas :
iris.assign(MaxSepalLen = iris.groupby("Species")["Sepal.Length"].transform('max'))