Skip to content

Instantly share code, notes, and snippets.

# Parameters for our Synthetic Network
num_of_nodes = 100 # Total number of nodes (which are, in our case, people)
edges_per_node = 4 # Amount of relations a given person(node) will have by default
prob_of_triangle = 0.1 # Chance of a triangle happening given a relation
# Defining The Network
G = nx.powerlaw_cluster_graph(num_of_nodes, edges_per_node, prob_of_triangle)
def scatter_y_label (var):
if var == 'total_cases':
return 'Percentage Infected'
elif var == 'total_tests':
return 'Percentage Tested'
elif var == 'total_deaths':
return 'Percentage Dead'
elif var == 'total_recovered':
return 'Percentage Recovered'
import dash
from dash.dependencies import Output, Input
import dash_core_components as dcc
import dash_html_components as html
import plotly.express as px
import pandas as pd
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
import dash
from dash.dependencies import Output, Input
import dash_core_components as dcc
import dash_html_components as html
import plotly.express as px
import pandas as pd
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
app = dash.Dash(__name__, external_stylesheets=external_stylesheets)
country population total_tests total_cases total_deaths total_recovered income_group expected_years_of_school
0 United States 331552784 119497624.0 8037789 220011.0 5184615.0 High income 12.9
1 India 1383826697 87872093.0 7173565 109894.0 6224792.0 Lower middle income 11.1
2 Brazil 212986866 17900000.0 5103408 150709.0 4495269.0 Upper middle income 11.9
3 Colombia 51035485 4202181.0 919083 27985.0 798396.0 Upper middle income 12.9
4 Spain 46759952 14590713.0 918223 33124.0 High income 13.0
# Defining the functio we'll use to convert the columns to snakecase
def to_snakecase (cols):
map_dict = {}
for col in cols:
map_dict[col] = col.lower().strip().replace(' ', '_')
return map_dict
# Defining the function we'll use to change the country names to the same format
country population total_tests total_cases total_deaths total_recovered
214 United States 331552784 119497624.0 8037789 220011.0 5184615.0
215 India 1383826697 87872093.0 7173565 109894.0 6224792.0
216 Brazil 212986866 17900000.0 5103408 150709.0 4495269.0
217 145952340 51191309.0 1312310 22722.0 1024235.0
218 Colombia 51035485 4202181.0 919083 27985.0 798396.0
country income_group expected_years_of_school
0 Afghanistan Low income 8.9
1 Albania Upper middle income 12.9
2 Algeria Lower middle income 11.8
3 Angola Lower middle income 8.1
4 Antigua and Barbuda High income 13.0
state republican_votes liberal_votes total_votes
Washington 1584651 2369612 3954263
Oregon 958448 1340383 2298831
California 5973237 11073361 17046598
Arizona 1661686 1672143 3333829
Nevada 669890 703486 1373376
Utah 865140 560282 1425422
Idaho 554128 287031 841159
Montana 343647 244836 588483
Wyoming 193559 73491 267050
country population total_tests total_cases total_deaths total_recovered income_group expected_years_of_school
0 United States 331552784 119497624.0 8037789 220011.0 5184615.0 High income 12.9
1 India 1383826697 87872093.0 7173565 109894.0 6224792.0 Lower middle income 11.1
2 Brazil 212986866 17900000.0 5103408 150709.0 4495269.0 Upper middle income 11.9
3 Colombia 51035485 4202181.0 919083 27985.0 798396.0 Upper middle income 12.9
4 Spain 46759952 14590713.0 918223 33124.0 High income 13.0
5 Argentina 45312730 2239514.0 903730 24186.0 732582.0 Upper middle income 12.9
6 Peru 33100421 4092566.0 851171 33357.0 748097.0 Upper middle income 13.0
7 Mexico 129313982 2088941.0 817503 83781.0 594180.0 Upper middle income 12.8
8 France 65314670 12394558.0 743479 32779.0 100828.0 High income 13.8