Skip to content

Instantly share code, notes, and snippets.

@Ayeeta
Ayeeta / ca_2018.py
Created September 11, 2019 12:27
visualize international migrant settlement in California
ca_international_mig_2018 = px.line(california, x = 'Area_Name', y='INTERNATIONAL_MIG_2018', title="International Migration to Califonia 2018")
ca_international_mig_2018.show()
@Ayeeta
Ayeeta / tx_2018.py
Created September 11, 2019 12:32
visualize international migrant settlements in Texas 2018
tx_international_mig_2018 = px.line(texas, x = 'Area_Name', y='INTERNATIONAL_MIG_2018', title="International Migration to Texas 2018")
tx_international_mig_2018.show()
@Ayeeta
Ayeeta / top_4.py
Created September 11, 2019 12:38
visualize the trend for the top 4 destinations for the past 9 years
trace0 = go.Scatter(
x = years_mig,
y = fl_international_mig,
mode = "lines",
name = "Florida"
)
trace1 = go.Scatter(
x = years_mig,
y = ny_international_mig,
@Ayeeta
Ayeeta / florida_df.py
Created September 11, 2019 12:54
Create florida data frame for international migrations for years 2010-2018
fl = population_data.loc[population_data['Area_Name'] == 'Florida']
fl_2010 = fl['INTERNATIONAL_MIG_2010'].tolist()
fl_2011 = fl['INTERNATIONAL_MIG_2011'].tolist()
fl_2012 = fl['INTERNATIONAL_MIG_2012'].tolist()
fl_2013 = fl['INTERNATIONAL_MIG_2013'].tolist()
fl_2014 = fl['INTERNATIONAL_MIG_2014'].tolist()
fl_2015 = fl['INTERNATIONAL_MIG_2015'].tolist()
fl_2016 = fl['INTERNATIONAL_MIG_2016'].tolist()
fl_2017 = fl['INTERNATIONAL_MIG_2017'].tolist()
fl_2018 = fl['INTERNATIONAL_MIG_2018'].tolist()
@Ayeeta
Ayeeta / florida_predict.py
Created September 11, 2019 13:11
Linear regression on Florida
X = fl_df.iloc[:, 0].values.reshape(-1, 1) # values converts it into a numpy array
Y = fl_df.iloc[:, 1].values.reshape(-1, 1) # -1 means that calculate the dimension of rows, but have 1 column
linear_regressor = LinearRegression() # create object for the class
linear_regressor.fit(X, Y) # perform linear regression
Y_pred = linear_regressor.predict(X) # make predictions
plt.scatter(X, Y)
plt.plot(X, Y_pred, color='red')
plt.show()
@Ayeeta
Ayeeta / florida_choropleth.py
Created September 11, 2019 13:24
Visualize settlements in florida
florida['text'] = "International Migration 2018"+"\
"+ florida["INTERNATIONAL_MIG_2018"].astype(str) + " " +"County:" +" \
"+ florida["Area_Name"]
values = florida['INTERNATIONAL_MIG_2018'].tolist()
fips = florida['FIPS'].tolist()
endpts = list(np.mgrid[min(values):max(values):4j])
colorscale = [
@Ayeeta
Ayeeta / florida_choropleth2.py
Created September 11, 2019 13:28
visualize internation migrant settlement 2018 in florida
x = florida['FIPS'].tolist()
fips = [str(i) for i in x]
values = florida['INTERNATIONAL_MIG_2018'].tolist()
fig = ff.create_choropleth(fips=fips, values=values)
fig.layout.template = None
fig.show()
@Ayeeta
Ayeeta / import_libraries.py
Created September 11, 2019 13:52
Libraries for datascience project
from matplotlib.pyplot import figure
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from pandas import DataFrame
from plotly.subplots import make_subplots
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import plotly.express as px
import plotly.graph_objects as go
@Ayeeta
Ayeeta / read_csv.py
Created September 11, 2019 13:54
read csv file-population_estimates.csv
#Read csv file and load to population data data frame
population_data = pd.read_csv(".../population_estimates.csv")
@Ayeeta
Ayeeta / population_data_head.py
Created September 11, 2019 13:56
To get a sense of the columns in our data and what they hold
population_data.head()