image_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

import warnings

import numpy as np
import pandas as pd
import warnings
warnings.filterwarnings('ignore')
import plotly.express as px
import matplotlib.pyplot as plt
import seaborn as sns
import os
kaggle_survey_2019 = pd.read_csv('../input/kaggle-survey-2019/multiple_choice_responses.csv')
kaggle_survey_2020 = pd.read_csv('../input/kaggle-survey-2020/kaggle_survey_2020_responses.csv')
kaggle_survey_2021 = pd.read_csv('../input/kaggle-survey-2021/kaggle_survey_2021_responses.csv')
indo_survey_2019 = kaggle_survey_2019[kaggle_survey_2019['Q3'] == 'Indonesia']
indo_survey_2020 = kaggle_survey_2020[kaggle_survey_2020['Q3'] == 'Indonesia']
indo_survey_2021 = kaggle_survey_2021[kaggle_survey_2021['Q3'] == 'Indonesia']

# kaggle_survey_2019 = kaggle_survey_2019[kaggle_survey_2019['Q3']=='Indonesia'].drop\
# (kaggle_survey_2019.columns[0], axis=1)
# kaggle_survey_2019.head()
# question = pd.read_csv('../input/kaggle-survey-2019/questions_only.csv')
# question.columns
# question_list = question.loc[0].tolist()
# question_list
f, ax = plt.subplots(nrows=1, ncols=3, figsize=(15,4))
barcolors = ['darkseagreen', 'peru', 'navy']

barstyle = {"edgecolor":"black", "linewidth":0.5}

indo_survey_2019['Q2'].value_counts().plot.bar(ax=ax[0], color=barcolors[0])
ax[0].set_title("2019")
indo_survey_2020['Q2'].value_counts().plot.bar(ax=ax[1], color=barcolors[1])
ax[1].set_title("2020")
indo_survey_2021['Q2'].value_counts().plot.bar(ax=ax[2], color=barcolors[2])
ax[2].set_title("2021")
plt.show()
    

def roleDanSize(df):
    newdf = df.groupby(['Q4', 'Q5']).size()
    newdf = newdf.to_frame(name='size').reset_index()
    newdf['role'] = newdf['Q4'] + '-' + newdf['Q5']
    newdf = newdf.drop(columns=['Q4', 'Q5']).sort_values(by=['size'])
    return newdf
data_2019 = roleDanSize(indo_survey_2019)
plt.barh(data_2019['role'], data_2019['size'])

data_2020 = roleDanSize(indo_survey_2020)
plt.barh(data_2020['role'], data_2020['size'])

data_2021 = roleDanSize(indo_survey_2021)
plt.barh(data_2021['role'], data_2021['size'])

def getting_values(rng):
    """
    fungsi bantuan untuk mengeluarkan nilai value_counts() setiap column Q9_Part_1-8 ke
    dalam bentuk dictionary
    """
    for i in range(1, rng):
        yield indo_survey_2019['Q9_Part_' + str(i)].value_counts().to_dict()
values = []
keys = []
for i in getting_values(9):
    values.append(list(i.values()))
    keys.append(list(i.keys()))
values = [j for sub in values for j in sub]
keys = [j for sub in keys for j in sub]

mypie = plt.pie(values, startangle=0, autopct='%1.0f%%', pctdistance=0.9, radius=1.2)
plt.title('Important part of your role at work', weight='bold', size=12)
plt.legend(mypie[0], keys, bbox_to_anchor=(1, 1))
plt.show()