Skip to content

Instantly share code, notes, and snippets.

View rohithteja's full-sized avatar

Rohith Teja M rohithteja

  • CEA (Commissariat à l'énergie atomique et aux énergies alternatives)
  • Paris
View GitHub Profile
@rohithteja
rohithteja / paris-choropleth.py
Created October 15, 2022 00:01
Choropleth city
import contextily as cx
# read data
df = gpd.read_file('data/arrondissements/arrondissements.shp',encoding='utf-8')
df = df.to_crs(epsg=3857)
fig, ax = plt.subplots(1, figsize=(10, 6),dpi=300,facecolor='w',edgecolor='w')
# colorbar
divider = make_axes_locatable(ax)
cax = divider.append_axes('right', size='5%', pad=0.3)
@rohithteja
rohithteja / geopandas-county.py
Created October 14, 2022 22:34
Choropleth Geopandas County
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/fips-unemp-16.csv", dtype={"fips": str})
df.rename(columns={'fips':'GEOID'}, inplace=True)
# read US county shapefile
county_map = gpd.read_file('data/cb_2018_us_county_500k/cb_2018_us_county_500k.shp')
county_map = county_map[~county_map.STATEFP.isin(['02','15','72','60','66','69','78','11'])]
county_map = county_map.to_crs("EPSG:2163")
# read US state shapefile
state_map = gpd.read_file('data/cb_2018_us_state_500k/cb_2018_us_state_500k.shp')
@rohithteja
rohithteja / geopandas-choropleth.py
Last active October 14, 2022 21:54
Choropleth geopandas
import pandas as pd
import geopandas as gpd
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
# read data
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_us_ag_exports.csv')
df.rename(columns={'code':'STUSPS'}, inplace=True)
# read US state shapefile
@rohithteja
rohithteja / plotly-choropleth.py
Created October 14, 2022 12:52
Choropleth plotly express
import pandas as pd
import geopandas as gpd
import plotly.express as px
# read data
df = pd.read_csv('data/population.csv',header=2)
df.rename(columns={'Country Code':'iso3'}, inplace=True)
# read shapefile
map = gpd.read_file('data/world-administrative-boundaries/world-administrative-boundaries.shp')
# merge df and shapefile
@rohithteja
rohithteja / gooey_example.py
Last active May 20, 2022 14:31
Gooey Example
from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser
from sklearn.datasets import make_classification
from sklearn.decomposition import PCA
from sklearn.manifold import LocallyLinearEmbedding
from sklearn.linear_model import LogisticRegression
from sklearn.svm import SVC
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from gooey import Gooey
@rohithteja
rohithteja / loop.sh
Last active May 3, 2022 08:26
Looping experiments using shell script
for dim_red_type in 'pca' 'lle'; do
for n_comp in 5 10; do
for classifier in 'lr' 'svc' 'rf'; do
echo $dim_red_type $n_comp $classifier
python argparse_automate.py --dim_red_type "${dim_red_type}" --n_comp "${n_comp}" --classifier "${classifier}"
done
done
done
@rohithteja
rohithteja / argparse_automate.py
Last active May 3, 2022 08:14
Argparse wrapper
from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser
def parse_args():
parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter,
conflict_handler='resolve')
parser.add_argument('--dim_red_type', default='pca', choices=[
'pca','lle'], help='The dim red. types')
parser.add_argument('--n_comp', default=10,type=int, choices=[
5,10], help='output dimensions')
parser.add_argument('--classifier', default='lr', choices=[
@rohithteja
rohithteja / dimred.py
Last active April 28, 2022 21:49
Sample code with dimensionality reduction and binary classification
from sklearn.datasets import make_classification
from sklearn.decomposition import PCA
from sklearn.manifold import LocallyLinearEmbedding
from sklearn.linear_model import LogisticRegression
from sklearn.svm import SVC
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
# arguments
@rohithteja
rohithteja / streamlit-crypto.py
Created March 11, 2022 15:20
Streamlit Structure
import streamlit as st
st.set_page_config(layout="wide")
#-------------------
# Streamlit Sidebar
#-------------------
fiat = ['USD','EUR','GBP']
tokens = df_scrape.Symbol.values
@rohithteja
rohithteja / plotlytable.py
Created March 11, 2022 14:41
Plotly table
df_scrape["color"] = df_scrape["% Change"].map(lambda x:'red' if x<0 else 'green')
cols_to_show = ['Name','Token', 'Price', '% Change', 'Market Cap']
# to change color of "% change" column
fill_color = []
n = len(df_scrape)
for col in cols_to_show:
if col!='% Change':
fill_color.append(['black']*n)
else: