text_plain_output_1.png
import matplotlib.ticker as mtick

import pandas as pd

df = pd.read_csv('../input/churn-prediction/Churn.csv')

df.shape

df.isna().sum()

df.dtypes

df['TotalCharges'] = df.TotalCharges.convert_objects(convert_numeric=True)

df['tenure_range'] = pd.cut(df.tenure, [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75], right=True)

df.dropna(inplace=True)

df = df.drop('tenure', axis=1)

gender_dis = (df['gender'].value_counts() * 100 / len(df)).plot(kind='bar', stacked=True)
gender_dis.set_ylabel('% Customers')
gender_dis.set_xlabel('Gender')
gender_dis.yaxis.set_major_formatter(mtick.PercentFormatter())
totals = []
for i in gender_dis.patches:
    totals.append(i.get_width())
total = sum(totals)
for i in gender_dis.patches:
    gender_dis.text(i.get_x() + 0.15, i.get_height() + 3.9, str(round(i.get_height() / total, 1)) + '%', fontsize=12, color='black')