text_html_output_1.png text_plain_output_2.png application_vnd.jupyter.stderr_output_1.png
from plotly.offline import init_notebook_mode, iplot

from plotly.offline import init_notebook_mode, iplot

import matplotlib.pyplot as plt

import pandas as pd

import plotly.graph_objs as go

import plotly.graph_objs as go

data = pd.read_csv('/kaggle/input/kaggle-survey-2020/kaggle_survey_2020_responses.csv')
df = data.iloc[1:, :]

init_notebook_mode(connected=True)
col = 'Q1'
v1 = df[col].value_counts().reset_index()
v1 = v1.rename(columns={col: 'count', 'index': col})
v1 = v1.sort_values(col)
trace1 = go.Bar(x=v1[col], y=v1['count'], marker=dict())
layout = {'title': 'Age Distribution', 'xaxis': {'title': 'Age Group'}, 'yaxis': {'title': 'Count'}}
fig = go.Figure(data=[trace1], layout=layout)

import plotly
import plotly.graph_objs as go
from plotly.offline import init_notebook_mode, iplot
init_notebook_mode(connected=True)
col = 'Q2'
grouped = df[col].value_counts().reset_index()
grouped = grouped.rename(columns={col: 'count', 'index': col})
trace = go.Pie(labels=grouped[col], values=grouped['count'], pull=[0.05, 0])
layout = {'title': 'Gender Distribution'}
fig = go.Figure(data=[trace], layout=layout)

d1 = df[df['Q2'] == 'Man']
d2 = df[df['Q2'] == 'Woman']
col = 'Q1'
v1 = d1[col].value_counts().reset_index()
v1 = v1.rename(columns={col: 'count', 'index': col})
v1['percent'] = v1['count'].apply(lambda x: 100 * x / sum(v1['count']))
v1 = v1.sort_values(col)
v2 = d2[col].value_counts().reset_index()
v2 = v2.rename(columns={col: 'count', 'index': col})
v2['percent'] = v2['count'].apply(lambda x: 100 * x / sum(v2['count']))
v2 = v2.sort_values(col)
trace1 = go.Bar(x=v1[col], y=v1['count'], name='Man', marker=dict(color='rgb(26, 118, 255)'))
trace2 = go.Bar(x=v2[col], y=v2['count'], name='Woman', marker=dict(color='rgb(55, 83, 109)'))
y = [trace1, trace2]
layout = {'title': 'Age Distribution over the Gender', 'bargap': 0.2, 'bargroupgap': 0.1, 'xaxis': {'title': 'Age Distribution'}, 'yaxis': {'title': 'Count'}}
fig = go.Figure(data=y, layout=layout)
fig.layout.template = 'presentation'

plt.style.use('fivethirtyeight')
col = 'Q3'
v2 = df[col].value_counts().reset_index()
v2 = v2.rename(columns={col: 'count', 'index': col})
v2 = v2.sort_values(by='count', ascending=False)
plt.figure(figsize=(30, 12))
barplot = plt.bar(v2.Q3, v2['count'], color='black')
for bar in barplot:
    yval = bar.get_height()
    plt.text(bar.get_x() + bar.get_width() / 2.0, yval, int(yval), va='bottom')
plt.title(' Number of Respondents per Country')
plt.xticks(rotation=90)
plt.show()