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

data = pd.read_csv('../input/broadband-customers-base-churn-analysis/bbs_cust_base_scfy_20200210.csv')
df = data.copy()
df

df.drop('Unnamed: 19', axis=1, inplace=True)

df.churn.replace('N', '0', inplace=True)
df.churn.replace('Y', '1', inplace=True)
df.current_mth_churn.replace('N', '0', inplace=True)
df.current_mth_churn.replace('Y', '1', inplace=True)

df.churn = df.churn.astype(int)
df.current_mth_churn = df.churn.astype(int)

df.describe().T

def summary(df):
    Types = df.dtypes
    Counts = df.apply(lambda x: x.count())
    Uniques = df.apply(lambda x: x.unique().shape[0])
    Nulls = df.apply(lambda x: x.isnull().sum())
    cols = ['Types', 'Counts', 'Uniques', 'Nulls']
    str = pd.concat([Types, Counts, Uniques, Nulls], axis=1, sort=True)
    str.columns = cols
summary(df)

col = df.columns.to_list()
catcol = [_ for _ in col if df[_].nunique() < 30]

termination_reasion_code = df.term_reas_code.unique()
termination_reasion_code_description = df.term_reas_desc.unique()
termination_reasion = dict(zip(termination_reasion_code, termination_reasion_code_description))
termination_reasion

df.drop(columns=['bill_cycl', 'serv_type', 'serv_code', 'term_reas_desc'], inplace=True)
df.head()