text_plain_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

import numpy as np
import pandas as pd
pd.set_option('display.max_columns', 50)
import os
from scipy import stats
import matplotlib.pyplot as plt
import seaborn as sns

TRAIN_PATH = '/kaggle/input/hr-analytics-job-change-of-data-scientists/aug_train.csv'
TEST_PATH = '/kaggle/input/hr-analytics-job-change-of-data-scientists/aug_test.csv'

df = pd.read_csv(TRAIN_PATH)

print(f"Dataset has {len(df['city'].dropna().unique())} unique cities.")
print("_"*20)
print(f"Unique cities count:\n{df['city'].value_counts()}")
print("*"*50, end="\n\n")

fig, ax = plt.subplots(figsize=(12, 6))
sns.barplot(ax=ax, x=df['city'].value_counts().index[:10], y=df['city'].value_counts().values[:10], capsize=.2,palette="Blues_d")

ax.set_title("Unique city count bar chart",fontsize=16)
ax.set_xlabel("City",fontsize=14)
ax.set_ylabel("Count",fontsize=14)

plt.show()

city_with_dev = df.groupby(['city']).mean()['city_development_index'].reset_index()
city_with_dev = city_with_dev.sort_values(by=['city_development_index'], ascending=False).reset_index(drop=True)

fig, ax = plt.subplots(figsize=(16, 6))
sns.barplot(ax=ax, x=city_with_dev['city'][:15], 
            y=city_with_dev['city_development_index'][:15], 
            palette="Blues_d")

ax.set_title("Top 15 cities with best development index bar chart",fontsize=16)
ax.set_xlabel("City",fontsize=14)
ax.set_ylabel("Development Index",fontsize=14)

plt.show()

print(f"Dataset has {len(df['gender'].dropna().unique())} unique gender's data.")
print("_"*20)
print(f"Unique Gender counts:\n{df['gender'].value_counts()}")
print("*"*50, end="\n\n")

total = df.shape[0]
total_male = df.query("gender == 'Male'")
total_female = df.query("gender == 'Female'")
total_other = df.query("gender == 'Other'")

male_percent = round(len(total_male)*100/total, 3)
female_percent = round(len(total_female)*100/total, 3)
other_percent = round(len(total_female)*100/total, 3)

labels = 'Male Percentage', 'Female Percentage', 'Other Percentage'
sizes = [male_percent, female_percent, other_percent]
explode = (0.05, 0.05, 0.05)

fig1, ax1 = plt.subplots()
ax1.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%',
        shadow=True, startangle=90)
ax1.axis('equal')
plt.title('Gender spread in Data', fontsize=15)
plt.savefig("./gender_pie.png")
plt.show()

total = len(df.query('target == 1.0'))
total_male_target = df.query("gender == 'Male' and target == 1.0")
total_female_target = df.query("gender == 'Female' and target == 1.0")
total_other_target = df.query("gender == 'Other' and target == 1.0")
male_target_percent = round(len(total_male_target) * 100 / total, 3)
female_target_percent = round(len(total_female_target) * 100 / total, 3)
other_target_percent = round(len(total_other_target) * 100 / total, 3)
labels = ('Male Percentage', 'Female Percentage', 'Other Percentage')
sizes = [male_target_percent, female_target_percent, other_target_percent]
explode = (0.1, 0.1, 0.1)
fig1, ax1 = plt.subplots()
ax1.pie(sizes, explode=explode, labels=labels, autopct='%1.1f%%', shadow=True, startangle=90)
ax1.axis('equal')
plt.title('Gender with target = 1.0', fontsize=15)
plt.savefig('./gender_target_1_pie.png')
plt.show()