My dataset is a telecommunication company’s customer data. It includes information related to the customer with variables such as gender, dependents, partner, type of internet service, phone service, customer tenure, if the customer pays for movie or tv streaming, monthly bill and payment method.
For my first visualization I created a bar chart comparing the count of service citation claims between male and female customers. My x-axis represents the two genders and my y-axis represents the count of customer service citation claims. I labeled the female bin as pink and the male bin as blue. Overall, male customers accounted for a larger amount of service citation calls at 3,555 compared to the female service citation count of 3,488.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import warnings
import matplotlib.patches as mpatches
warnings.filterwarnings("ignore")
path = "C:/Users/jack/OneDrive/Desktop/IS460 - O/Module 2/"
filename = path + 'TelcoCustomerData.csv'
df = pd.read_csv(filename)
male_count = (df['gender'] == 'Male')
male_count = male_count.sum()
female_count = (df['gender'] == 'Female')
female_count = female_count.sum()
total_gender_count = female_count + male_count
# Figure 1 - Bar Plot of Telco Customer Claims by Gender
fig = plt.figure(figsize = (18,10))
plt.bar('Male', male_count, color = 'blue', alpha = 0.8)
plt.bar('Female', female_count, color = 'pink', alpha = 0.8)
plt.title('Male vs Female Citation Count', fontsize = 18)
plt.xlabel('Gender', fontsize = 14)
plt.ylabel('Number of Service Citation Claims', fontsize = 14)
plt.text('Male', male_count, str(male_count), fontsize = 14, fontweight = 'bold')
plt.text('Female', female_count, str(female_count), fontsize = 14, fontweight = 'bold')
plt.show()
For my second visualization, I wanted to examine the three price ranges of bills of customers paying for the three available types of internet service. My x-axis represents the three available services while my y-axis represents the range of monthly customer bill prices. The three types of service are DSL, fiber optic, and no internet service labeled as “no”.
The most expensive of the two actual internet services is fiber optic which has a scatter price range of around $70/month to $120/month. The other internet service, DSL had a slightly lower but larger range of around $30/month to $90/month. The no internet category has the smallest and lowest range at around $20/month to $30/month for customers who do not pay for any kind of internet service. Customers that have fiber optic internet tend to pay the greatest amount of money on their monthly bill compared to the other two options.
# I added these two lines as I had some errors when knitting my rmarkdown code
import os
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = 'c:/users/jack/Anaconda3/Library/plugins/platforms'
#JPerry IS460 Module 2 Final Deliverable
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import warnings
import matplotlib.patches as mpatches
warnings.filterwarnings("ignore")
path = "C:/Users/jack/OneDrive/Desktop/IS460 - O/Module 2/"
filename = path + 'TelcoCustomerData.csv'
df = pd.read_csv(filename)
#print(df.columns)
# Figure 2 - Scatterplot of Monthly Bill Charges Based on the type of Customer Internet Service
MonthlyCharges = df.MonthlyCharges
MonthlyCharges
InternetService = df.InternetService
tenure = df.tenure
tenure
fig = plt.figure(figsize = (18,10))
plt.scatter(InternetService, MonthlyCharges)
plt.title('Monthly Cost of Types of Internet Service', fontsize = 18)
plt.xlabel('Types of Internet Service', fontsize = 14)
plt.ylabel('Monthly Bill Cost ($)', fontsize = 14)
For my third visualization, I decided to examine the monthly charges of customers broken up by the amount of months they have been with the company in months. My x-axis represents the number of months the customer has been with the company and the y-axis represents the average monthly charges each tenured group pays monthly.
I decided to split the customers into three groups representing three different levels of customer tenure, the pink representing new customers or those under 20 months at the company, orange representing customers that have been with the company for longer than 20 but less than 50 months, and the long term customers in green that are customers who have been with the company for greater than 50 months.
I also added a plot and trend line to examine the average monthly charges and the general trend of the graph. Examining the graph, as customers increase in their time spent at the company, their monthly bill price tends to slightly increase. In context this means that the longer a customer spends as a customer at this company, the greater their monthly bill increases.
def pick_colors_according_to_mean_count(df):
colors = []
avg = df['tenure'].mean()
for tenure in df['tenure']:
if tenure < 20:
colors.append('pink')
elif tenure < 50:
colors.append('orange')
else:
colors.append('green')
return colors
New_Customer = mpatches.Patch(color = 'pink', label = 'New Customers (under 20 months)')
Middle_Term_Customer = mpatches.Patch(color = 'orange', label = 'Middle Term Customers (above 20 months but below 50 months)')
Long_Term_Customer = mpatches.Patch(color = 'green', label = 'Long Term Customers (Above 50 months)')
# Figure 3 - monthly charges of customer tenure months
mean_charges_per_tenure = df.groupby('tenure')['MonthlyCharges'].mean().reset_index()
plt.figure(figsize=(18, 10))
colors = pick_colors_according_to_mean_count(df) # Ensure this function is defined
plt.bar(df['tenure'], df['MonthlyCharges'], color=colors)
plt.title('Monthly Charges by Tenure Months', fontsize=18)
plt.xlabel('Months Spent as Customer at Company', fontsize=18, labelpad=20)
plt.ylabel('Average Monthly Charges by Tenure Group', fontsize=18, labelpad=20)
# Now plot the mean charges per tenure as a scatter plot on top of the bar chart
plt.scatter(mean_charges_per_tenure['tenure'], mean_charges_per_tenure['MonthlyCharges'], color='blue')
# Fit and plot a trend line
z = np.polyfit(mean_charges_per_tenure['tenure'], mean_charges_per_tenure['MonthlyCharges'], 1)
p = np.poly1d(z)
plt.plot(mean_charges_per_tenure['tenure'], p(mean_charges_per_tenure['tenure']), "r--")
# legend
plt.legend(loc = 'lower right',
handles = [New_Customer, Middle_Term_Customer, Long_Term_Customer],
fontsize = 14,
frameon = True,
shadow = True)
plt.show()
For my fourth visualization, I decided to create a bar plot that examines customers that have dependents and their preferred media streaming preference. My x-axis includes two bins, one green that represents the number of dependents that prefer to stream tv and on the right, one blue representing the group of dependents that prefers to stream movies. My y-axis is a count of the number of customer dependents.
Examining the bar chart, I decided to also include the counts of each of the bins alongside their label on the x-axis for easy access and legibility. For customers that have dependents, streaming tv holds a greater count and is therefore more popular than customers with dependents who stream movies. The count for customers with dependents that prefer to stream tv is 785 while the count for customers with dependents that prefer to stream movies is 756.
# dependents == yes
yes_dependents = (df['Dependents'] == 'Yes')
yes_dependents_count = yes_dependents.sum()
# StreamingTV == yes
yes_TV = (df['StreamingTV'] == 'Yes')
yes_TV = yes_TV & yes_dependents
yes_TV_count = yes_TV.sum()
# filter the dataframe for TV
filteredTVDF = df[yes_TV]
filteredTVDF = filteredTVDF.count()
# StreamingMovies == Yes
yes_Movies = (df['StreamingMovies'] == 'Yes')
yes_Movies = yes_Movies & yes_dependents
yes_Movies_count = yes_Movies.sum()
# filter the dataframe for Movies
filteredMoviesDF = df[yes_Movies]
filteredMoviesDF = filteredMoviesDF.count()
# legend setup
filteredTVDF_legend = mpatches.Patch(color = 'lightgreen', label = "Number of Customers with \n Dependents that Stream TV")
filteredMoviesDF_legend = mpatches.Patch(color = 'lightblue', label = "Number of Customers with \n Dependents that Stream Movies")
# Figure 4 - relationship between dependents and popularity of StreamingTV vs Streaming Movies
fig = plt.figure(figsize = (18, 10))
plt.bar("Number of Dependents that Stream TV - "+ str(yes_TV_count),
filteredTVDF, color = 'lightgreen', alpha = 0.8)
plt.bar("Number of Dependents that Stream Movies - " + str(yes_Movies_count),
filteredMoviesDF, color = 'lightblue', alpha = 0.8)
plt.xlabel('Types of Customers Dependents Media Preference', fontsize = 18, labelpad = 20)
plt.ylabel('Count of Customer Dependents', fontsize = 18, labelpad = 20)
plt.title('Telco Customer Dependents Media Preference Count', fontsize = 20)
# legend
plt.legend(loc = 'lower right',
handles = [filteredTVDF_legend, filteredMoviesDF_legend],
fontsize = 14,
frameon = True,
shadow = True)
plt.show()
For my fifth and final visualization, I wanted to determine which payment method among customers is the most popular for monthly bill payment. On my x-axis I have my four payment methods, green represents the number of customers using electronic checks, pink represents the number of customers using mailed checks, maroon represents the number of customers using an automatic bank transfer, and light blue reprsents the number of customers using automatic credit transfer. The y-axis includes the count of payment methods.
Examining the graph, it is clear that the green bin representing the number of customers using electronic checks, is the most popular at 2,365. The other three bins are all near each other, with mailed checks as the second most popular payment method at a count of 1,612 then automatic bank transfer as the third most popular payment method at 1,544. Of the four payment methods, the most unpopular payment method is the automatic credit transfer represented by light blue at 1,522.
#df['Contract']
#df['PaymentMethod']
# Frequency of Payment Groups - Electronic Check
electronic_check_count = (df['PaymentMethod'] == 'Electronic check').sum()
# Frequency of Payment Groups - Mailed Check
mailed_check_count = (df['PaymentMethod'] == 'Mailed check').sum()
# Frequency of Payment Groups - Bank transfer (automatic)
auto_bank_transfer_count = (df['PaymentMethod'] == 'Bank transfer (automatic)').sum()
# Frequency of Payment Groups - Credit card (automatic)
auto_credit_transfer_count = (df['PaymentMethod'] == 'Credit card (automatic)').sum()
# legend setup
electronic_check_count_legend = mpatches.Patch(color = 'lightgreen', label = "Number of Customers Using Electronic Checks")
mailed_check_count_legend = mpatches.Patch(color = 'pink', label = "Number of Customers Using Mailed Checks")
auto_bank_transfer_count_legend = mpatches.Patch(color = 'maroon', label = "Number of Customers Using Automatic Bank Transfer")
auto_credit_transfer_count_legend = mpatches.Patch(color = 'lightblue', label = "Number of Customers Using Automatic Credit Transfer")
# Figure 5 - Bar Plot of Most Popular Bill Payment Methods
fig = plt.figure(figsize = (18, 10))
x_pos = np.arange(4)
plt.bar(x_pos,[electronic_check_count,
mailed_check_count,
auto_bank_transfer_count,
auto_credit_transfer_count],
color = ['lightgreen','pink','maroon','lightblue'])
plt.xlabel('Payment Methods', fontsize = 18, labelpad = 20)
plt.ylabel('Count of Payment Methods', fontsize = 18, labelpad = 20)
plt.title('Count of Customer Bill Payment Methods', fontsize = 20)
plt.xticks(x_pos)
plt.text(x_pos[0], electronic_check_count,electronic_check_count, ha = 'center', va = 'center', fontsize = 14)
plt.text(x_pos[1], mailed_check_count,mailed_check_count, ha = 'center', va = 'center', fontsize = 14)
plt.text(x_pos[2], auto_bank_transfer_count,auto_bank_transfer_count, ha = 'center', va = 'center', fontsize = 14)
plt.text(x_pos[3], auto_credit_transfer_count,auto_credit_transfer_count, ha = 'center', va = 'center', fontsize = 14)
plt.legend(loc = 'upper right',
handles = [electronic_check_count_legend,
mailed_check_count_legend,
auto_bank_transfer_count_legend,
auto_credit_transfer_count_legend],
fontsize = 14,
frameon = True,
shadow = True)
plt.show()