In [1]:
%%capture
import numpy as np
import pandas as pd
import os
# Suppress unwatned warnings
import warnings
warnings.filterwarnings('ignore')
import logging
logging.getLogger("requests").setLevel(logging.WARNING)
# Load our favorite visualization library
import plotly
import plotly.plotly as py
import plotly.figure_factory as ff
import plotly.graph_objs as go
import cufflinks as cf
plotly.offline.init_notebook_mode(connected=True)
# Sign into Plotly with masked, encrypted API key
myPlotlyKey = os.environ['SECRET_ENV_BRETTS_PLOTLY_KEY']
py.sign_in(username='bretto777',api_key=myPlotlyKey)
# Set some defaults for how pandas displays
pd.set_option('display.height', 1000)
pd.set_option('display.max_rows', 200)
pd.set_option('display.max_columns', 500)
pd.set_option('display.width', 1000)
In [27]:
fig = {
"data": [
{
"values": churnDF['Churn'].value_counts(),
"labels": churnDF['Churn'].unique(),
"domain": {"x": [0, .48]},
"name": "Predicted to Churn",
"hoverinfo":"label+percent+name",
"hole": .4,
"type": "pie"
},
{
"values": churnDF['CustServ Calls'].value_counts(),
"textposition":"inside",
"domain": {"x": [.52, 1]},
"name": "Customer Service Calls",
"hoverinfo":"label+value+name",
"hole": .4,
"type": "pie"
}],
"layout": {
"title":"Customer Churn Predictions",
"annotations": [
{
"font": {
"size": 20
},
"showarrow": False,
"text": "Churn",
"x": 0.20,
"y": 0.5
},
{
"font": {
"size": 20
},
"showarrow": False,
"text": "Calls",
"x": 0.8,
"y": 0.5
}
]
}
}
py.iplot(fig, filename='donut')
Out[27]:
In [2]:
s3file = 'https://dsclouddata.s3.amazonaws.com/churn.csv'
churnDF = pd.read_csv(s3file, delimiter=',')
churnDF.head(5)
Out[2]: