Skip to content

Instantly share code, notes, and snippets.

View joonro's full-sized avatar

Joon Ro joonro

View GitHub Profile
@joonro
joonro / multiprocessing_cal_d.py
Last active June 8, 2023 14:23
[General Multiprocessing of pandas.DataFrame with multiple arguments] Using multiple arguments, spliting pandas.DataFrame #python #multiprocessing #pandas
import numpy as np
import pandas as pd
def cal_d(partial_panel, nvid_jt, movchr, r_all):
for r, row in enumerate(partial_panel.itertuples()):
showdate = pd.Timestamp(str(row.showdate))
nvid = row.nvid
reldate = movchr.at[nvid, 'reldate']
@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 / Qualtrics.SurveyEngine.getEmbeddedData.js
Last active March 18, 2022 18:06
[Qualtrics/Store and retrieve embedded data] This example is with time calculation since the survey start #qualtrics #JavaScript
Qualtrics.SurveyEngine.addOnload(function()
{
/*Place your JavaScript here to run when the page loads*/
var currentTime = new Date();
var hours = currentTime.getHours();
var minutes = currentTime.getMinutes();
var current_time_in_minutes = hours * 60 + minutes
@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 / 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 / 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):