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 / README.md
Last active November 17, 2015 20:43
d3-introduction
@yassineAlouini
yassineAlouini / README.md
Last active November 17, 2015 13:45
hexbin
@yassineAlouini
yassineAlouini / README.md
Last active November 25, 2015 19:15
gaussian-histogram
@yassineAlouini
yassineAlouini / .block
Last active July 14, 2016 13:35
simple shapes
license: mit

Keybase proof

I hereby claim:

  • I am yassineAlouini on github.
  • I am yassinealouini (https://keybase.io/yassinealouini) on keybase.
  • I have a public key whose fingerprint is 638C BEFB DFA5 9085 67F1 7C16 BCA5 905F 4A55 3726

To claim this, I am signing this object:

@yassineAlouini
yassineAlouini / csv_to_geojson.py
Created January 19, 2017 09:57
Load a CSV file with latitude and longitude columns and transform it into a GeoJSON.
import pandas as pd
import geopandas as gpd
from shapely.geometry import Point
import json
def df_to_gdf(input_df):
"""
Convert a DataFrame with longitude and latitude columns
to a GeoDataFrame.
@yassineAlouini
yassineAlouini / df_to_xls.py
Last active May 31, 2017 13:40
Save a Pandas DataFrame to Excel
# You need to install xlsxwriter: pip install xlsxwriter
import pandas as pd
import StringIO
def save_df_to_xls(input_df, fp, sheet_name='report'):
df = input_df.copy()
writer = pd.ExcelWriter(fp, engine='xlsxwriter',
datetime_format='d/mm/yyyy') # Datatime format for french users
df.to_excel(writer, index=False, sheet_name=sheet_name, encoding='utf-8) # Encoding for french users
@yassineAlouini
yassineAlouini / tar_gz_from_s3.py
Last active July 17, 2017 13:13
Download a tar.gz archive from s3
import s3fs
s3 = s3fs.S3FileSystem()
S3_BUCKET = ''
BASE_KEY = ''
def get_data_from_s3(file_name):
key = BASE_KEY.format('data', file_name)
s3.get('s3://{}/{}'.format(S3_BUCKET, key), '/tmp/{}'.format(file_name))
dfs = []
@yassineAlouini
yassineAlouini / bz2_compress.py
Created June 2, 2017 11:43
Compress a list of files using the BZ2 protocol.
import bz2
import glob
for fp in glob.iglob('path/to_files'):
with open(fp, 'rb') as f_input:
with bz2.BZ2File(fp + '.bz2', 'wb', compresslevel=9) as f_output:
f_output.write(f_input.read())
@yassineAlouini
yassineAlouini / clean_gdf.py
Created June 9, 2017 16:42
Buffer a GeoDataFrame then break Multi-polygons to Polygons.
import geopandas as gpd
import pandas as pd
def multipolygon_to_polygon(input_gdf):
"""Break each MultiPolygon to its constituting Polygons, create a new polygons DataFrame and then
append it to the initial GeoDataFrame
"""
gdf = input_gdf.copy()
multipolygon_gdf = gdf.loc[lambda df: df.geometry.geom_type == 'MultiPolygon', :]
for row_index, row in multipolygon_gdf.iterrows():