This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np, pandas as pd | |
df_len = 1000 # integer multiple of 4 | |
np.random.seed(42) | |
# create a random data frame | |
df = pd.DataFrame( | |
{ | |
"group_a": np.random.randint(0, df_len / 4, size=df_len), | |
"group_b": np.random.randint(0, df_len / 4, size=df_len), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# how to use np.where with multiple columns at once, even whole data frames? | |
import numpy as np | |
import pandas as pd | |
np.random.seed(42) | |
df1 = pd.DataFrame(np.random.randint(0, 100, size=(100, 4)), columns=list("ABCD")) | |
df2 = pd.DataFrame(np.random.randint(0, 100, size=(100, 4)), columns=list("ABCD")) | |
condition = pd.Series(np.random.choice(a=[False, True], size=100, p=[.1, .9])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See `curl.md`. Here is the R equivalent. | |
library(httr) | |
library(jsonlite) | |
make_page <- function(url, headers, data) { | |
response <- POST( | |
url = url, | |
body = toJSON(data, auto_unbox = TRUE), | |
config = add_headers(.headers = headers) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// background | |
function timer(ms) { return new Promise(res => setTimeout(res, ms)); } | |
async function keepGoing(direction, i) { | |
await timer(500); | |
const directions = {"up": "previous", "down": "next"}; | |
document.querySelectorAll(`[data-qa="fixed-footer-navigation-${directions[direction]}"]`)[0].click() | |
await timer(500); | |
let focusQ = document.querySelectorAll('[data-qa-focused="true"]')[0] | |
let qId = focusQ.getAttribute('data-qa-blockref'); |
OlderNewer