Dataset

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.

Findings

Visualization 1 - Citation Bar Chart

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()

Visualization 2 - Internet Service Scatter Plot

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)

Visualization 3 - Monthly Charges Tenure Bar Plot

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()                    

Visualization 4 - Telco Customer Dependents Media Preference Bar Plot

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()