Skip to content

Instantly share code, notes, and snippets.

View joonro's full-sized avatar

Joon Ro joonro

View GitHub Profile
@joonro
joonro / formula.org
Created November 28, 2022 21:21
[orgmode table frequently used formula] #orgmode #emacs
  • $ (e.g., $4) represents columns, @ (e.g., @2) represents rows.
  • $> means the last column.

Last row sum of all above:

@joonro
joonro / price_elasticity_XP.sql
Created September 24, 2021 17:15
[Uber Freight: Price Elasticity XP] #sql #querybuilder
/*
- 2021-09-24 Received this from He
*/
with elasticity_xp as
(select
msg.load_uuid
, max_by(msg.elasticity_experiment.pre_xp_price, ts) as pre_xp_price
, max_by(msg.elasticity_experiment.post_xp_price, ts) as post_xp_price
, max_by(msg.elasticity_experiment.perturbation_factor, ts) as perturbation_factor
@joonro
joonro / freeze a func with a function argument.py
Created June 23, 2021 15:45
[Freeze a function with a function argument with partial] I guess it should work, but I can freeze a function with function arguments as well. https://docs.python.org/3/library/functools.html#functools.partial #python #multiprocessing
# test partial
from functools import partial
def frozen_func():
return 2
def target_func(x, frozen_func):
numpy.seterr(all='raise')
@joonro
joonro / IPython.display.py
Created May 22, 2021 23:12
[IPython.display] Import `display` function for jupyter notebooks #python
from IPython.display import display
@joonro
joonro / UTC_timestamps.py
Last active March 27, 2020 22:42
[Python dealing with UTC timestamps] 2020-03-27 It seems this method is accurate because it explicitly specifies UTC time. #pyhton #time
import datetime
# get UTC timestamp in seconds
datetime_utc_origin = datetime.datetime(1970, 1, 1)
# now
utc_timestamp_now = (datetime.datetime.utcnow() - datetime_utc_origin).total_seconds()
@joonro
joonro / prob_choose_r_randomly_from_n_questions.py
Created December 10, 2019 06:03
[Probability of randomly choose r correct answers out of n total questions] #python #teaching
import math
n = 33 # number of questions
r = 6 # number of correct answers
probs = []
for r in range(n):
@joonro
joonro / pandas_groupby_date_and_time.py
Created November 11, 2019 16:22
[pandas groupby date and time] #python
# specify time frequency of groupby
groupby_freq = 'W'
gr = df.groupby(
pd.Grouper(key='date', freq=groupby_freq)
)
@joonro
joonro / matplotlib bar chart interaction.py
Last active June 9, 2021 16:08
[pandas/matplotlib bar chart] #python #plot #matplotlib #pandas
# 2021-06-09 This is older way
import matplotlib.pyplot as plt
def plot_bar_chart_interaction(
means_var1_low,
means_var1_high,
var1_name="",
var2_name="",
title="",
@joonro
joonro / pandas Colored Corr.py
Created July 25, 2019 05:02
[pandas DataFrame Correlation Matrix with Colored Entries] Remove lower-tri elements, make large numbers red #python #pandas #color #DataFrame
def color_large_value_red(val):
"""
Takes a scalar and returns a string with
the css property `'color: red'` for absolute values > 0.5,
black otherwise.
"""
try:
float_val = float(val)
color = 'red' if (abs(float_val) > 0.4) and (float_val != 1) else 'black'