text_plain_output_1.png image_output_1.png
import matplotlib.pyplot as plt

import matplotlib.pyplot as plt

import pandas as pd

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

import seaborn as sns

data = pd.read_csv('/kaggle/input/adult-census-income/adult.csv', na_values='?')

data.shape

data.columns = ['age', 'workclass', 'fnlwgt', 'education', 'education_num', 'marital_status', 'occupation', 'relationship', 'race', 'sex', 'capital_gain', 'capital_loss', 'hours_per_week', 'native_country', 'income']

data.isna().sum()

data = data.replace({'<=50K': 0, '>50K': 1})
data = data.replace({'<=50K': 0, '>50K': 1})

data.corr()

eda_percentage = data['income'].value_counts(normalize = True).rename_axis('income').reset_index(name = 'Percentage')
ax = sns.barplot(x = 'income', y = 'Percentage', data = eda_percentage.head(10), palette='RdGy_r')
eda_percentage

plt.figure(figsize=(12, 6))
order_list = ['Less than 18', '19-30', '31-40', '41-50', '51-60', '61-70', 'Greater than 70']
sns.countplot(data['age_group'], hue=data['income'], palette='autumn_r', order=order_list)
plt.title('Income of Individuals of Different Age Groups', fontsize=18)
plt.xticks(fontsize=16)
plt.yticks(fontsize=16)
plt.legend(fontsize=16)