Created
May 25, 2019 10:46
-
-
Save karamanbk/dac10f93d2f3f3efa6663b1a93371bee to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#plotting monthly charge | |
df_plot = df_data.copy() | |
df_plot['MonthlyCharges'] = df_plot['MonthlyCharges'].astype(int) | |
df_plot = df_plot.groupby('MonthlyCharges').Churn.mean().reset_index() | |
plot_data = [ | |
go.Scatter( | |
x=df_plot['MonthlyCharges'], | |
y=df_plot['Churn'], | |
mode='markers', | |
name='Low', | |
marker= dict(size= 7, | |
line= dict(width=1), | |
color= 'blue', | |
opacity= 0.8 | |
), | |
) | |
] | |
plot_layout = go.Layout( | |
yaxis= {'title': "Churn Rate"}, | |
xaxis= {'title': "Monthly Charges"}, | |
title='Monthly Charge vs Churn rate', | |
plot_bgcolor = "rgb(243,243,243)", | |
paper_bgcolor = "rgb(243,243,243)", | |
) | |
fig = go.Figure(data=plot_data, layout=plot_layout) | |
pyoff.iplot(fig) | |
#plotting total charges -- needed some engineering because of null values | |
df_data.loc[pd.to_numeric(df_data['TotalCharges'], errors='coerce').isnull(),'TotalCharges'] = np.nan | |
df_data = df_data.dropna() #dropping null values | |
df_data['TotalCharges'] = pd.to_numeric(df_data['TotalCharges'], errors='coerce') | |
df_plot = df_data.copy() | |
df_plot['TotalCharges'] = df_plot['TotalCharges'].astype(int) | |
df_plot = df_plot.groupby('TotalCharges').Churn.mean().reset_index() | |
df_plot = df_data.copy() | |
df_plot['TotalCharges'] = df_plot['TotalCharges'].astype(int) | |
df_plot = df_plot.groupby('TotalCharges').Churn.mean().reset_index() | |
df_plot = df_data.copy() | |
df_plot['TotalCharges'] = df_plot['TotalCharges'].astype(int) | |
df_plot = df_plot.groupby('TotalCharges').Churn.mean().reset_index() | |
plot_data = [ | |
go.Scatter( | |
x=df_plot['TotalCharges'], | |
y=df_plot['Churn'], | |
mode='markers', | |
name='Low', | |
marker= dict(size= 7, | |
line= dict(width=1), | |
color= 'blue', | |
opacity= 0.8 | |
), | |
) | |
] | |
plot_layout = go.Layout( | |
yaxis= {'title': "Churn Rate"}, | |
xaxis= {'title': "Total Charges"}, | |
title='Total Charge vs Churn rate', | |
plot_bgcolor = "rgb(243,243,243)", | |
paper_bgcolor = "rgb(243,243,243)", | |
) | |
fig = go.Figure(data=plot_data, layout=plot_layout) | |
pyoff.iplot(fig) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment