Skip to content

Instantly share code, notes, and snippets.

Useful Git commands

The laziest way to delete all unused branches safely except master:

git checkout master
git branch | xargs git branch -d

Merge master into current feature branch:

Create presentations with jupyter notebook

Convert notebook to presentation:

jupyter nbconvert slideshow.ipynb --to slides --post serve

Jupyter Lab commands

execute command line in cell with !:

! pip freeze
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

merge two dfs on specific key

df.set_index('key').join(df2.set_index('key'))

get datetime from String

pd.to_datetime(df['date'],format='%Y-%m-%d')

get weekday of datetime

@AlexandraKapp
AlexandraKapp / pypi_package.md
Last active October 9, 2019 21:14
Upload Package to PyPI

Upload Package to PyPI

  1. create package distribution python setup.py sdist bdist_wheel

  2. Test if Package is without errors twine check dist/*

  3. upload package python -m twine upload dist/*

@AlexandraKapp
AlexandraKapp / data_to_plr.py
Created September 23, 2019 13:55
Merge data with Berlin Planungsraeume
import geopandas as gpd
import pandas as pd
from shapely.geometry import Point
plr = gpd.read_file('data/lor_planungsraeume.geojson', encoding='utf-8')
df = pd.read_csv('data/DATAFILE.csv', sep=";", dtype={'PLR_CODES':str}, na_values=['OTHER_NAN_VALUES'])
df.set_index('PLR_CODES', inplace=True)
data = df.join(plr.set_index('spatial_name'), rsuffix='_r')