Skip to content

Instantly share code, notes, and snippets.

@csaid
Last active March 30, 2016 18:55
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 csaid/55bb1c932546abfa8601555b0e7cf9a7 to your computer and use it in GitHub Desktop.
Save csaid/55bb1c932546abfa8601555b0e7cf9a7 to your computer and use it in GitHub Desktop.
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