Skip to content

Instantly share code, notes, and snippets.

View dataninjato's full-sized avatar

Sebastian dataninjato

  • Germany
  • 01:48 (UTC +02:00)
View GitHub Profile
@dataninjato
dataninjato / lambda_comprehensions.py
Last active August 10, 2022 11:38
lambda + comprehension combinations
# Convert function to lambda expr
l1 = lambda x, y: x if x > y else y
# dict comprehension
l2 = lambda s: { char:s.count(char) for char in s}
# numbers tuple fed into list comprehsion
l3 = lambda *nums: math.sqrt(sum([n**2 for n in nums]))
# multiple conditions in dict comprehension
@dataninjato
dataninjato / proportion_effectsize.py
Created July 13, 2022 20:49 — forked from DustinAlandzes/gist:2832d75c36b0963781035239f98f1c3e
Calculating sample size with statsmodels in python (3% base conversion, 5% relative Minimum Detectable Effect (MDE) = 3.15%)
from statmodels.stats.power import tt_ind_solve_power
from statsmodels.stats.proportion import proportion_effectsize
es = proportion_effectsize(0.03, 0.0315)
n = tt_ind_solve_power(effect_size=es, ratio=1, power=0.8, alpha=0.05)
# from https://speakerdeck.com/nneu/b-testing-a-bayesian-approach?slide=36
@dataninjato
dataninjato / pandas.py
Last active January 25, 2022 19:40
collection
# Subset for categories with at least 250 apps
large_categories = apps_with_size_and_rating_present.groupby('Category').filter(lambda x: len(x) >= 250)
# Thus, it filters out only rows that doesn't have NaN values in 'name' column.
filtered_df = df[df['name'].notnull()]
# Multi Merge DFs
ridership_cal_stations = ridership.merge(cal, on=['year','month','day']).merge(stations, on='station_id')
# Group by ward, pop_2010, and vacant, then count the # of accounts