This file contains hidden or 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 pytz | |
import pandas as pd | |
def localize_datetime(input_df, timezone='Europe/Paris', | |
datetime_column='tms_gmt'): | |
""" | |
Convert datetime column from UTC to another timezone. | |
""" | |
tmz = pytz.timezone(timezone) | |
df = input_df.copy() |
This file contains hidden or 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
from __future__ import absolute_import | |
from __future__ import division | |
from __future__ import print_function | |
from __future__ import unicode_literals |
This file contains hidden or 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
# Inspired from here: https://bokeh.pydata.org/en/latest/docs/user_guide/geo.html | |
from bokeh.tile_providers import CARTODBPOSITRON | |
from bokeh.io import output_file, show | |
from bokeh.plotting import figure | |
bound = 20000000 # meters | |
fig = figure(tools='pan, wheel_zoom', x_range=(-bound, bound), y_range=(-bound, bound)) | |
fig.axis.visible = False | |
fig.add_tile(CARTODBPOSITRON) | |
show(fig) |
This file contains hidden or 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 elo | |
import pandas as pd | |
from slacker import Slacker | |
from tabulate import tabulate | |
import emoji | |
slack = Slacker('SLACK_API_KEY') # API key | |
test = False | |
game = True | |
K_FACTOR = 40 |
This file contains hidden or 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 pandas as pd | |
df = pd.DataFrame({'t': [1, 2, 3, 4, 5, 6], 'sid': [1, 1, 1, 2, 2, 2], 'time': [1, 2, 2, 2, 1, 1]}) | |
hist_df = df.groupby(['sid', 'time']).t.value_counts(bins=[1, 2, 3, 10]).reset_index(name='counts') |
This file contains hidden or 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 geopandas as gpd | |
import numpy as np | |
# Set a seed for reproducibility | |
np.random.seed(0) | |
input_path = 'input/path/to/geojson' | |
output_path = 'output/path/to/geojson' | |
choices = [1, 2, 3] |
This file contains hidden or 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 pandas as pd | |
import itertools | |
import numpy as np | |
# From here: https://pandas.pydata.org/pandas-docs/stable/cookbook.html#creating-example-data | |
def expand_grid(data_dict): | |
rows = itertools.product(*data_dict.values()) | |
return pd.DataFrame.from_records(rows, columns=data_dict.keys()) |
This file contains hidden or 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
from shapely import wkb | |
import numpy as np | |
from functools import wraps | |
def vectorize(**vectorize_kwargs): | |
""" A (numpy) vectorizing decorator | |
""" | |
def _vectorize(func): | |
@wraps(func) | |
def wrapper(*args, **kwargs): |
This file contains hidden or 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
# Inspired from here: https://stackoverflow.com/questions/17095101/outputting-difference-in-two-pandas-dataframes-side-by-side-highlighting-the-d | |
def _show_dfs_difference(df1, df2): | |
ne_stacked = (df1 != df2).stack() | |
difference_locations = np.where(df1 != df2) | |
changed = ne_stacked[ne_stacked] | |
changed_from = df1.values[difference_locations] | |
changed_to = df2.values[difference_locations] | |
return pd.DataFrame({'from': changed_from, 'to': changed_to}, index=changed.index) |
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
from functools import wraps | |
import numpy as np | |
from shapely import wkb | |
def vectorize(**vectorize_kwargs): | |
""" A (numpy) vectorizing decorator |