text_plain_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/customer-personality-analysis/marketing_campaign.csv', delimiter='\\t', engine='python')

df_mod = df
df_mod['Dt_Customer'] = pd.to_datetime(df['Dt_Customer'], format='%d-%m-%Y')
df_mod['Age'] = max(df_mod.Dt_Customer.dt.year) - df['Year_Birth']
df_mod = df.rename(columns={'Response': 'AcceptedCmp6'})
df_mod = df_mod.drop(columns=['Z_Revenue', 'Z_CostContact'])

df_mod.dropna(inplace=True)

df_mod.Complain.value_counts()

df_mod.drop(columns=['Complain'], inplace=True)

Discount_matrix = df_mod[sorted([i for i in df_mod.columns if i.startswith('Acc')])]

l = {}
k = []
for i in range(len(Discount_matrix)):
    for j in Discount_matrix.columns:
        if Discount_matrix.iloc[i][j] != 0:
            l[i] = int(j[-1])
            break
        else:
            l[i] = 0
df_mod['No_first_accepted'] = l.values()

df_mod['total_accepted'] = np.sum(Discount_matrix, axis=1)
df_mod['accepted_any'] = np.where(df_mod['total_accepted'] != 0, 1, 0)

df_mod.loc[np.isin(df_mod['Marital_Status'], ['YOLO', 'Absurd', 'Alone']), 'Marital_Status'] = 'Single'
df_mod['Marital_Status'].value_counts()

fig, axs = plt.subplots(1, 3, figsize=(12, 6))
fig.patch.set_facecolor('white')
sns.histplot(df_mod, x='No_first_accepted', ax=axs[0])
sns.histplot(df_mod, x='accepted_any', ax=axs[1])
sns.histplot(df_mod, x='total_accepted', ax=axs[2])