Skip to content

Instantly share code, notes, and snippets.

@csaid csaid/diamonds.py
Last active Mar 30, 2016

Embed
What would you like to do?
import pandas as pd
from ggplot import diamonds
# 1) How do I easily create multiple summaries of multiple columns?
(
diamonds
.groupby('cut')
.agg(??) # Equivalent of summarize(mean_x = mean(x), var_xy = var(xy))
)
# 2) How do I easily put multiple summaries back into the original data frame?
(
diamonds
.groupby('cut')
.?? # Equivalent of mutate(mean_x = mean(x), var_xy = var(xy))?
)
# 3) Not a huge deal, but creating new columns with .assign is more verbose than mutate()
(
diamonds
.assign(xy = lambda d: d.x + d.y, xz = lambda d: d.x + d.z)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.