image_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

data = pd.read_csv('../input/kaggle-survey-2020/kaggle_survey_2020_responses.csv')

data.shape

def datainfo(df):
    return pd.DataFrame([(col, df[col].nunique(), df[col].isna().sum(), df[col].dtype, df[col].unique()[:5]) for col in df.columns], columns=['name', 'nunique', 'missing', 'dtype', 'values :5'])

question = data.iloc[0, :]
data = data.iloc[1:, :]

fig,ax=plt.subplots(1,1,figsize=(8,5),dpi=200)

dataQ1=data['Q1'].value_counts().sort_index()

ax.bar(dataQ1.index,dataQ1)
plt.show()

dataQ2=data['Q2'].apply(lambda x:'x' if x not in ['Man','Woman'] else x)

fig,ax=plt.subplots(1,1,figsize=(8,5),dpi=200)

dataQ2=dataQ2.loc[dataQ2!='x'].value_counts()

ax.bar(dataQ2.index,dataQ2)
plt.show()

data['Q2']=data['Q2'].apply(lambda x:'x' if x not in ['Man','Woman'] else x)
gender=data[data['Q2']!='x'].groupby('Q2')['Q1'].value_counts().unstack()

man=gender.loc['Man']
woman=gender.loc['Woman']

fig,ax=plt.subplots(1,1,figsize=(8,6),dpi=200)

ax.bar(man.index,man)
ax.bar(woman.index,woman)

plt.show()

dataQ3=data['Q3'].value_counts()[:10]
fig,ax=plt.subplots(1,1,figsize=(8,6),dpi=200)

ax.barh(dataQ3.index,dataQ3)

plt.show()

dataQ4=data['Q4'].value_counts()[:10]
fig,ax=plt.subplots(1,1,figsize=(8,6),dpi=200)

ax.barh(dataQ4.index,dataQ4)

plt.show()

pd.options.display.float_format = lambda x: '{:.0f}'.format(x) if int(x) == x else '{:,.2f}'.format(x)
data.groupby('Q3')['Q5'].value_counts().unstack().style.background_gradient(cmap='Blues')

# pd.DataFrame(question).iloc[6]

dataQ6=data['Q6'][data['Q6'].notnull()].value_counts()

fig,ax=plt.subplots(1,1,figsize=(8,5),dpi=200)

ax.bar(dataQ6.index,dataQ6)
ax.set_xticklabels(dataQ6.index,Rotation=59)
plt.show()

fig, ax = plt.subplots(1, 1, figsize=(8, 6), dpi=200)
sns.heatmap(data[data['Q6'].notnull()].groupby('Q6')['Q4'].value_counts().unstack(), ax=ax, square=True, annot=True, fmt='d', cmap='Blues')
plt.show()