image_output_1.png
import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

import seaborn as sns

df = pd.read_csv('../input/bank-marketing/bank-full.csv')
marketing = df[['campaign', 'y']]
marketing.sample(5)

#Visualize the data

fig, (ax1, ax2) = plt.subplots(1,2, figsize=(8,8))
sns.histplot(data=marketing, x='y', ax=ax1)
sns.boxplot(data=marketing, x='y', y='campaign', ax=ax2)
plt.show()

df_bank = marketing.groupby(['y']).apply(lambda x: x.sample(n=199, random_state=123))
df_bank.drop(columns='y', axis=1, inplace=True)
df_bank.reset_index(inplace=True)
df_bank.drop(columns='level_1', axis=1, inplace=True)
df_bank.groupby('y')['campaign'].count()

df_bank.groupby('y').agg({'campaign': ['median', 'mean']})

fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 8))
sns.barplot(data=df_bank, x='y', y='campaign', estimator=np.median, ax=ax1)
sns.barplot(data=df_bank, x='y', y='campaign', ax=ax2)
plt.show()