Skip to content

Instantly share code, notes, and snippets.

Shinichi Okada shinokada

View GitHub Profile
View facet_row.py
import plotly.express as px
fig = px.bar(df, x="race", color="gender",
y='value',
title="A Grouped Bar Chart With Plotly Express in Python",
barmode='group',
height=700,
facet_row="gender"
)
fig.show()
View facet_col.py
import plotly.express as px
fig = px.bar(df, x="race", color="gender",
y='value',
title="A Grouped Bar Chart With Plotly Express in Python",
barmode='group',
height=700,
facet_col="gender"
)
fig.show()
View grouped_bar_chart_4.py
fig = px.bar(df, x="race", color="gender",
y='value',
title="A Grouped Bar Chart With Plotly Express in Python",
barmode='group',
height=600
)
fig.show()
View grouped_bar_chart_3.py
df=pd.melt(df,id_vars=['race'],var_name='gender', value_name='value')
df
View grouped_bar_chart_2.py
cols = [2,10,14]
rows = [33,36,39,42,45,48,51,57]
df =df.iloc[rows,cols].reset_index(drop=True)
df.columns=['race','Male','Female']
for col in ['Male', 'Female']:
df[col]=pd.to_numeric(df[col].str.replace('%',''))
display(df)
View grouped_bar_chart.py
import pandas as pd
import plotly.express as px
url='https://gist.githubusercontent.com/shinokada/f2ebf82eaa3cfa02106ae93c7fe9efbe/raw/3494b1e2ba9b1c0d8991e71483123f63b4bce559/educational+attainment.csv'
df = pd.read_csv(url)
display(df)
View educational+attainment.csv
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 7.
"","","","","United States","","","","","","","","","","",""
"","","","","Total","","Percent","","Male","","Percent Male","","Female","","Percent Female",""
"","","","","Estimate","Margin of Error","Estimate","Margin of Error","Estimate","Margin of Error","Estimate","Margin of Error","Estimate","Margin of Error","Estimate","Margin of Error"
"AGE BY EDUCATIONAL ATTAINMENT","AGE BY EDUCATIONAL ATTAINMENT","","","","","","","","","","","","","",""
"Population 18 to 24 years","AGE BY EDUCATIONAL ATTAINMENT","Population 18 to 24 years","","30,656,350","+/-47,866","(X)","(X)","15,699,747","+/-30,705","(X)","(X)","14,956,603","+/-26,503","(X)","(X)"
"Less than high school graduate","AGE BY EDUCATIONAL ATTAINMENT","Population 18 to 24 years","Less than high school graduate","3,839,148","+/-37,376","12.5%","+/-0.1","2,235,271","+/-28,109","14.2%","+/-0.2","1,603,877","+/-23,062","10.7%","+/-0.2"
"High school graduate (includes equivalency)","AGE BY EDUCATIONAL ATTAINMENT","Population 18 to 24 years","High school gradu
View MPVDatasetDownload1.csv
We can't make this file beautiful and searchable because it's too large.
Victim's name,Victim's age,Victim's gender,Victim's race,URL of image of victim,Date of Incident (month/day/year),Street Address of Incident,City,State,Zipcode,County,Agency responsible for death,Cause of death,A brief description of the circumstances surrounding the death,Official disposition of death (justified or other),Criminal Charges?,Link to news article or photo of official document,Symptoms of mental illness?,Unarmed,Alleged Weapon (Source: WaPo),Alleged Threat Level (Source: WaPo),Fleeing (Source: WaPo),Body Camera (Source: WaPo),WaPo ID (If included in WaPo database),Off-Duty Killing?,Geography (via Trulia methodology based on zipcode population density: http://jedkolko.com/wp-content/uploads/2015/05/full-ZCTA-urban-suburban-rural-classification.xlsx ),ID,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Eric M. Tellez,28,Male,White,https://fatalencounters.org/wp-content/uploads/2020/01/Eric-M.-Tellez-Jr..jpg,2019/12/31,Broad St. ,Globe,AZ,85501,Gila,Globe Police Department,Gunshot,"After midnight, a patrol o
View MPVDatasetDownload1.csv
We can't make this file beautiful and searchable because it's too large.
Victim's name,Victim's age,Victim's gender,Victim's race,URL of image of victim,Date of Incident (month/day/year),Street Address of Incident,City,State,Zipcode,County,Agency responsible for death,Cause of death,A brief description of the circumstances surrounding the death,Official disposition of death (justified or other),Criminal Charges?,Link to news article or photo of official document,Symptoms of mental illness?,Unarmed,Alleged Weapon (Source: WaPo),Alleged Threat Level (Source: WaPo),Fleeing (Source: WaPo),Body Camera (Source: WaPo),WaPo ID (If included in WaPo database),Off-Duty Killing?,Geography (via Trulia methodology based on zipcode population density: http://jedkolko.com/wp-content/uploads/2015/05/full-ZCTA-urban-suburban-rural-classification.xlsx ),ID,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
View MPVDatasetDownload1.csv
We can't make this file beautiful and searchable because it's too large.
Victim's name,Victim's age,Victim's gender,Victim's race,URL of image of victim,Date of Incident (month/day/year),Street Address of Incident,City,State,Zipcode,County,Agency responsible for death,Cause of death,A brief description of the circumstances surrounding the death,Official disposition of death (justified or other),Criminal Charges?,Link to news article or photo of official document,Symptoms of mental illness?,Unarmed,Alleged Weapon (Source: WaPo),Alleged Threat Level (Source: WaPo),Fleeing (Source: WaPo),Body Camera (Source: WaPo),WaPo ID (If included in WaPo database),Off-Duty Killing?,Geography (via Trulia methodology based on zipcode population density: http://jedkolko.com/wp-content/uploads/2015/05/full-ZCTA-urban-suburban-rural-classification.xlsx ),ID,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
You can’t perform that action at this time.