Skip to content

Instantly share code, notes, and snippets.

View ayoskovich's full-sized avatar
🏠
Working from home

Anthony Yoskovich ayoskovich

🏠
Working from home
View GitHub Profile
@ayoskovich
ayoskovich / top_n.py
Last active September 5, 2020 19:37
Top / bottom 3 values of column named 'lat'.
df.nlargest(3, 'lat')
df.nsmallest(3, 'lat')
@ayoskovich
ayoskovich / counts_prop.py
Created August 17, 2020 19:12
Create table containing counts AND proportions.
# 'counts' will be the name of the new column
# 'date' will be the index of the dataframe
x = df['date'].value_counts().to_frame('counts')
x['prop'] = x['counts'] / x['counts'].sum()
@ayoskovich
ayoskovich / format_line.vim
Last active September 5, 2020 19:37
Split a line into 2 columns on a comma, making the second column 50 characters after the first.
qa0f,100a <Esc>50|dwjq
@ayoskovich
ayoskovich / jupyter_remove_nums_and_output.py
Created August 30, 2020 02:08
Add this to jupyter_notebook_config.py in order to auto remove cell numbers and output from jupyter notebooks.
def scrub_output_pre_save(model, **kwargs):
"""scrub output before saving notebooks"""
# only run on notebooks
if model['type'] != 'notebook':
return
# only run on nbformat v4
if model['content']['nbformat'] != 4:
return
for cell in model['content']['cells']:
@ayoskovich
ayoskovich / k_submit.sh
Created August 30, 2020 21:37
Submit a results file to kaggle.
kaggle competitions submit -f <file> -m <message> <competition>
@ayoskovich
ayoskovich / get_coef.py
Created September 3, 2020 18:37
Get coefficients out of a sklearn pipeline.
pipeline.named_steps['logisticregression'].coef_
@ayoskovich
ayoskovich / set_reference.py
Created September 4, 2020 14:16
Set the reference category when using statsmodels
model = ols("SalePrice ~ C(LandContour, Treatment(reference='Lvl'))", data=df).fit()
@ayoskovich
ayoskovich / any_greater.py
Created September 5, 2020 15:13
Return df rows where any of multiple columns are above a certain number.
df[df.apply(lambda x: np.any(x > 100_000), axis=1, raw=True)]
@ayoskovich
ayoskovich / retina_display.py
Created September 6, 2020 00:42
Configure Jupiter notebook to show figures on retina displays.
%config InlineBackend.figure_format='retina'
@ayoskovich
ayoskovich / entr_jupyter_notebooks.sh
Last active October 9, 2020 00:34
Autoexport all jupyter notebooks to .py files
ls *.ipynb | entr jupyter nbconvert *.ipynb --to python --output-dir=./src