Skip to content

Instantly share code, notes, and snippets.

# R
# 1) Easily create multiple summaries of multiple column.
diamonds %>%
group_by(cut) %>%
summarize(mean_x = mean(x), var_xy = var(x * y))
# 2) Easily put multiple summaries back into the original data frame
diamonds %>%
group_by(cut) %>%
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))
)
from dplython import *
diamonds >> group_by(X.cut) >> summarize(mean_x = np.mean(X.x), var_y = np.var(X.y))
diamonds >> group_by(X.cut) >> mutate(mean_x = np.mean(X.x), var_y = np.var(X.y))
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import cps
import seaborn as sns
sns.set_style('white')
plt.ion()
# This is a quick hack that gets the job done :/
def repulsion(arr):
@csaid
csaid / shower_problem_tau_samples.csv
Last active February 9, 2020 17:12
20,000 shower samples that can be used to solve the shower problem described in https://chris-said.io/2020/02/08/the-shower-problem/. Direction (left of right) is sampled from Bernoulli trials. Tau is sampled from a two-parameter Weibull distribution, using scipy's weibull_min: weibull_min.rvs(1.5, loc=0, scale=50, size=20_000)
direction tau
1.0 44.17309441579963
1.0 39.13313136222197
1.0 2.229445925263579
1.0 45.51885740055968
1.0 32.46369490822559
0.0 34.32693114812909
1.0 29.851265008411353
1.0 22.108872716835183
0.0 39.32300084317585
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.