Data visualisations made by Janhavi Pimplikar
A student at Pimpri Chinchwad College of Engineering
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import plotly as py
from plotly.offline import iplot
import cufflinks as cf
py.offline.init_notebook_mode(connected=True)
import seaborn as sns
cf.go_offline()
import plotly.express as px
abc=pd.read_csv('USVoters.csv')
abc
ABC=abc.groupby('Abbr.').sum().reset_index()
ABC
fig=px.choropleth(ABC,locations='Abbr.',locationmode='USA-states',color=np.log(ABC['Total Population']),hover_name='Abbr.',color_continuous_scale=px.colors.sequential.Inferno,scope='usa',range_color=(0,20),title='US population by State')
fig.update(layout_coloraxis_showscale=True)
fig.show()
AGE=abc.groupby('Age')['Total Population'].sum()
AGE
fig,ax=plt.subplots(figsize=(10,10))
AGE.plot.pie(y='Total Population',legend=True,shadow=True,colors=sns.color_palette('Set2'),ax=ax,autopct='%1.2f%%',fontsize=15)
c=plt.Circle((0,0),0.3,color='white')
plt.gca().add_artist(c)
plt.legend(loc='upper right')
plt.ylabel('Total US population by age group',size=15)
fig.show()
fig=px.choropleth(ABC,locations='Abbr.',locationmode='USA-states',color=np.log(ABC['Citizen Population']),hover_name='Abbr.',color_continuous_scale=px.colors.sequential.Viridis,scope='usa',range_color=(0,20),title='US citizen population by State')
fig.update(layout_coloraxis_showscale=True)
fig.show()
fig,ax=plt.subplots(figsize=(10,10))
AGE.plot.pie(y='Citizen Population',legend=True,shadow=True,colors=sns.color_palette('Pastel1'),ax=ax,autopct='%1.2f%%',fontsize=15)
c=plt.Circle((0,0),0.3,color='white')
plt.gca().add_artist(c)
plt.legend(loc='upper right')
plt.ylabel('US citizen population by age group',size=15)
fig.show()
sns.jointplot(x='Total Population',y='Citizen Population',color='red',data=ABC,height=8)
plt.xticks(size=20)
plt.yticks(size=20)
sns.set_style('darkgrid')
ABC.iplot(x='Abbr.',y='Registered Voters',kind='bar',color='purple',xTitle='States',yTitle='Registered Voters',title='Number of Registered voters per state')
ABC.iplot(x='Citizen Population',y='Registered Voters',mode='markers',color='lightgreen',xTitle='Citizen Population',yTitle='Registered Voters',title='Relational analysis between citizens and registered voters')
sns.catplot(x='Age',y='Registered Voters',kind='violin',height=8,aspect=2,data=abc,palette='rainbow')
plt.xlabel('Age groups',size=20)
plt.xticks(size=20)
plt.ylabel('Number of Registered Voters',size=20)
plt.yticks(size=20)
plt.title('Frequency of Registered voters by age',size=20)
ABC.iplot(x='Abbr.',y='Confirmed Voters',kind='bar',color='fuchsia',xTitle='States',yTitle='Confirmed Voters',title='Number of Confirmed voters per state')
ABC.iplot(x='Citizen Population',y='Confirmed Voters',mode='markers',color='navy',xTitle='Citizen Population',yTitle='Confirmed Voters',title='Relational analysis between citizens and confirmed voters')
sns.catplot(x='Age',y='Confirmed Voters',kind='violin',height=8,aspect=2,data=abc,palette='twilight')
plt.xlabel('Age groups',size=20)
plt.xticks(size=20)
plt.ylabel('Number of Confirmed Voters',size=20)
plt.yticks(size=20)
plt.title('Frequency of confirmed voters by age',size=20)
#voter turnout %=(confirmed voters/registered voters)*100
ABC['Voter Turnout in %']=(ABC['Confirmed Voters']/ABC['Registered Voters'])*100
ABC
ABC_edited=ABC.sort_values('Voter Turnout in %',ascending=False,inplace=True)
ABC_edited=ABC.head(10)
ABC_edited
fig=px.choropleth(ABC_edited,locations='Abbr.',locationmode='USA-states',color='Voter Turnout in %',hover_name='Abbr.',color_continuous_scale=px.colors.sequential.Electric,title='States with the highest turnout',scope="usa")
fig.update(layout_coloraxis_showscale=True)
fig.show()
dataset imported from the resources from https://www.udemy.com/course/data-analysis-with-excel-pivot-tables/
attributes: Websites such as stackoverflow.com, plotlyexpress.com, geeksforgeeks.com etc.