Skip to content

Instantly share code, notes, and snippets.

View joonro's full-sized avatar

Joon Ro joonro

View GitHub Profile
@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'
@joonro
joonro / statsmodels_highlight_sig_variables.py
Created March 31, 2019 18:13
[statsmodels highlight significant variables in result table] Highlight significant variables in result table using pandas.DataFrame.style #python #pandas #statsmodels
def highlight_row(row):
"""Highlight row with red color for variables with p < 0.05"""
color = ''
if row['P>|t|'] < 0.05:
color = 'red'
return ['color: %s' % color] * len(row.values)
df_result.style.apply(custom_style, axis=1).to_excel('results.xlsx')
@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 / profiling.sh
Created January 30, 2019 21:16
[Profiling] #python profiling and viewing with SnakeViz (http://jiffyclub.github.io/snakeviz/)
# you can pass command line argument as you normally would:
$ python -m cProfile -o mcmc_hmm.prof mcmc_hmm.py estimate --niter=20000
# Use SnakeViz (install with $ pip install snakeviz) to view the profile results:
$ snakeviz profile.prof
@joonro
joonro / pandas_HDFStore_load.py
Last active July 11, 2019 23:36
[pandas HDFStore] Storing and loading DataFrames via `pd.DataFrame`. #python #pandas
import pandas as pd
HDFStore = pd.HDFStore(os.path.join(home, 'Data/Name.ph5'), mode='r')
df = HDFStore['/df']
HDFStore.close()
@joonro
joonro / pandas_results.py
Created October 21, 2018 16:19
[Pandas DataFrame for output printing] #python
def print_results(mean_post, std_post):
"""Create Pandas DataFrame with results"""
num_digits = 3
result_table = mean_post.round(num_digits).astype(str)
str_std_post = std_post.round(num_digits).astype(str)
t_stat = mean_post / std_post
for col in result_table:
"""Add more 0's for 0.0"""
@joonro
joonro / Number of active users per day
Last active October 30, 2018 14:59
[Stackoverflow API Queries] Collection of queries that I tried #sql
# https://data.stackexchange.com/stackoverflow/query/918019
SELECT DISTINCT Cast(Posts.CreationDate as Date), COUNT(DISTINCT OwnerUserId)
FROM Posts
GROUP BY Cast(Posts.CreationDate as Date)
Order BY Cast(Posts.CreationDate as Date);
<style>
.Skin .SkinInner {min-width: 1000px!important;}
</style>
@joonro
joonro / power_analysis_linear_models.R
Last active August 20, 2018 03:52
[Power Analysis] Linear Model see https://www.statmethods.net/stats/power.html for documentation. #R
install.packages("pwr")
library(pwr)
Rsq_A = 0.302
Rsq_AB = 0.309
f2 = (Rsq_AB - Rsq_A) / (1 - Rsq_AB)
f2
pwr.f2.test(u=5, v=4000, f2=f2, sig.level=0.05)
@joonro
joonro / Add_Word_Count_After_Textbox
Created August 2, 2018 18:02
[Show Number of Words After Textbox] #qualtrics
Qualtrics.SurveyEngine.addOnReady(function()
{
var questionID = this.questionId;
var textbox =$('QR~' + questionID);
textbox.insert({after: '<br><span style="font-size: 14.4px;">Your word count is:&nbsp;</span><span id="wordCountDisplay">0</span>'}); var display = $('wordCountDisplay');
var display = $('wordCountDisplay');
var that = this;
function countWords(s){