Skip to content

Instantly share code, notes, and snippets.

View amitrani6's full-sized avatar

Alex Mitrani amitrani6

View GitHub Profile
import branca
# Create the map object
m = folium.Map(location=[48, -102], zoom_start=3)
# Create the colomap styles
colormap = branca.colormap.LinearColormap(
vmin=us_data_gdf["Total_Pop_2021"].quantile(0.0),
vmax=us_data_gdf["Total_Pop_2021"].quantile(1),
colors=["red", "orange", "lightblue", "green", "darkgreen"],
m = folium.Map(location=[48, -102], zoom_start=3)
folium.Choropleth(
geo_data=us_data_gdf,
name="choropleth",
data=us_data_gdf,
columns= ["GEOID","Total_Pop_2021"],
key_on="feature.properties.GEOID",
fill_color="YlGn",
fill_opacity=0.7,
m = folium.Map(location=[48, -102], zoom_start=3)
folium.Choropleth(
geo_data=usmap_gdf,
name="choropleth",
data=all_states_census_df,
columns= ["state_str","Total_Pop_2021"],
key_on="feature.id",
fill_color="YlGn",
fill_opacity=0.7,
m = folium.Map(location=[48, -102], zoom_start=3)
folium.Choropleth(
geo_data=usmap_json_with_id,
name="choropleth",
data=all_states_census_df,
columns=["state_str", "Total_Pop_2021"],
key_on="feature.id",
fill_color="YlGn",
fill_opacity=0.7,
# Import the folium library (only shown here once)
import folium
m = folium.Map(location=[48, -102], zoom_start=3)
folium.Choropleth(
geo_data=usmap_json_no_id,
name="choropleth",
data=all_states_census_df,
columns=["state", "Total_Pop_2021"],
@amitrani6
amitrani6 / time_series_transformation_code.py
Created January 10, 2020 03:49
Transformations of time series data
# Create transformation columns of the adjusted close price
# Calculate the log of the adjusted close prices
inx_df['adj_close_log'] = np.log(inx_df['adj_close'])
# Calculate the square root of the adjusted close prices
inx_df['adj_close_sqrt'] = np.sqrt(inx_df['adj_close'])
# Calculate the cubed root of the adjusted close prices
inx_df['adj_close_cbrt'] = np.cbrt(inx_df['adj_close'])
@amitrani6
amitrani6 / plotly_growth_rate_campbell.py
Created November 22, 2019 04:07
Solo Growth Rate Chart with Plotly
# Plotly Growth Rate Chart For The Campbell Soup Company
# Calculate Growth Rate
cpb['growth_rate'] = cpb['Adj Close'].pct_change()
s_and_p['growth_rate'] = s_and_p['Adj Close'].pct_change()
fig = go.Figure()
# You can add multiple traces, in this case financial securities
fig.add_trace(go.Scatter(x=cpb.Date, y=cpb['growth_rate'],
@amitrani6
amitrani6 / plotly_ohlc.py
Created November 22, 2019 03:50
OHLC with Plotly for the Campbell Soup Company
# A Plotly OHLC Chart With A Rangeslider
# This code is adapted from the Plotly site
# Source: https://plot.ly/python/ohlc-charts/
# Import the necessary libraries
import pandas as pd
import numpy as np
# The section of the Plotly library needed
import plotly.graph_objects as go
@amitrani6
amitrani6 / matplotlib_ohlc.py
Created November 22, 2019 03:32
Matplotlib OHLC Chart For The Campbell Soup Company
# This code was adapted from Harrison Kinsley's tutorial
# Source: https://pythonprogramming.net/candlestick-ohlc-graph-matplotlib-tutorial/
# Import the necessary libraries
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
import matplotlib.dates as mdates
import matplotlib.ticker as mticker
@amitrani6
amitrani6 / PCA_3D.py
Created November 10, 2019 23:05
PCA 3D Visualization Code
# The code to generate a 3-D plot of Seinfeld and Curb Your Enthusiasm
# scripts with dimensions identified with Principal Component Analysis
import matplotlib.pyplot as plt
seinfeld_3d = transformed_data_3d[:num_seinfeld]
s3_x = [i[0] for i in seinfeld_3d]
s3_y = [i[1] for i in seinfeld_3d]
s3_z = [i[2] for i in seinfeld_3d]