Built with blockbuilder.org
Built with blockbuilder.org
Built with blockbuilder.org
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
license: mit |
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:
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 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. |
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
# 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 |
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 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 = [] |
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 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()) |
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 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(): |
OlderNewer