Skip to content

Instantly share code, notes, and snippets.

View yassineAlouini's full-sized avatar
⚙️
PyTorch Exploration...

Yassine Alouini yassineAlouini

⚙️
PyTorch Exploration...
View GitHub Profile
@yassineAlouini
yassineAlouini / per_hour_plot.py
Last active September 4, 2018 08:59
One tick per hour matplotlib plot (using pandas)
import pandas as pd
import matplotlib.pylab as plt
import matplotlib.dates as mdates
hours = mdates.HourLocator(interval = 1)
h_d_fmt = mdates.DateFormatter('%d-%m %H:%M:%S')
DATA_PATH = "/path/to/your/data"
TMS_COL = "timestamp_column"
COL_TO_PLOT = "column_to_plot"
@yassineAlouini
yassineAlouini / instructions.md
Last active August 28, 2018 18:46
Publish to PyPi
  1. Update the version in the setup.py file.

  2. Run: python3 setup.py sdist bdist_wheel.

  3. Run the following: python setup.py sdist upload -r pypi.

Notice that this last command is deprecated. Use twine instead.

@yassineAlouini
yassineAlouini / vectorization.py
Created June 20, 2018 13:25
Some vectorized GIS operations
# -*- coding: utf-8 -*-
from functools import wraps
import numpy as np
from shapely import wkb
def vectorize(**vectorize_kwargs):
""" A (numpy) vectorizing decorator
@yassineAlouini
yassineAlouini / dfs_difference.py
Created May 17, 2018 08:34
Show DataFrame differences
# 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)
@yassineAlouini
yassineAlouini / vectorized_gis.py
Created April 27, 2018 12:22
Some vectorized GIS operations
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):
@yassineAlouini
yassineAlouini / expand_grid.py
Last active March 22, 2018 14:31
Create a DataFrame from all the possible combination of a dict
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())
@yassineAlouini
yassineAlouini / random_choice_to_geojson.py
Created February 28, 2018 15:55
Add a random choice column to GeoJSON file
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]
@yassineAlouini
yassineAlouini / multindex_histogram.py
Created February 21, 2018 09:38
Histogram computation on a multi-index
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')
@yassineAlouini
yassineAlouini / elo.py
Last active February 2, 2019 11:01
Script to update the ELO score after a new game. Works with two teams of multiple players.
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
@yassineAlouini
yassineAlouini / carto_bokeh_map.py
Created February 5, 2018 16:28
Use CartoDB as a tile provider for Bokeh
# 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)