#!/usr/bin/env python # coding: utf-8 # # Finding the Two Best Markets to Advertise in an E-learning Product # # In this project, we'll aim to find the two best markets to advertise our product in — we're working for an e-learning company that offers courses on programming. Most of our courses are on web and mobile development, but we also cover many other domains, like data science, game development, etc. # # We'll analyze existing data about new coders to find the best markets to invest in for advertisting. To make our recommendation, we'll try to find out: # # * Where are these new coders located. # * What are the locations with the greatest number of new coders. # * How much money new coders are willing to spend on learning. # # ### Summary of Results # # After analyzing the data, the only solid conclusion we reached is that the US would be a good market to advertise in. For the second best market, it wasn't clear-cut what to choose between India and Canada. We decided to send the results to the marketing team so they can use their domain knowledge to take the best decision. # # For more details, please refer to the the full analysis below. # # # Exploring Existing Data to Avoid Supplementary Costs with Surveys # # To avoid spending money on organizing a survey, we'll first try to make use of existing data to determine whether we can reach any reliable result. # # One good candidate for our purpose is [freeCodeCamp's 2017 New Coder Survey](https://medium.freecodecamp.org/we-asked-20-000-people-who-they-are-and-how-theyre-learning-to-code-fff5d668969). [freeCodeCamp](https://www.freecodecamp.org/) is a free e-learning platform that offers courses on web development. Because they run [a popular Medium publication](https://medium.freecodecamp.org/) (over 400,000 followers), their survey attracted new coders with varying interests (not only web development), which is ideal for the purpose of our analysis. # # The survey data is publicly available in [this GitHub repository](https://github.com/freeCodeCamp/2017-new-coder-survey). Below, we'll do a quick exploration of the `2017-fCC-New-Coders-Survey-Data.csv` file stored in the `clean-data` folder of the repository we just mentioned. We'll read in the file using the direct link [here](https://raw.githubusercontent.com/freeCodeCamp/2017-new-coder-survey/master/clean-data/2017-fCC-New-Coders-Survey-Data.csv). # In[1]: # Read in the data import pandas as pd direct_link = 'https://raw.githubusercontent.com/freeCodeCamp/2017-new-coder-survey/master/clean-data/2017-fCC-New-Coders-Survey-Data.csv' fcc = pd.read_csv(direct_link, low_memory = 0) # low_memory = False to silence dtypes warning # Quick exploration of the data print(fcc.shape) pd.options.display.max_columns = 150 # to avoid truncated output fcc.head() # # Checking for Sample Representativity # # As we mentioned in the introduction, most of our courses are on web and mobile development, but we also cover many other domains, like data science, game development, etc. For the purpose of our analysis, we want to answer questions about a population of new coders that are interested in the subjects we teach. We'd like to know: # # * Where are these new coders located. # * What locations have the greatest densities of new coders. # * How much money they're willing to spend on learning. # # So we first need to clarify whether the data set has the right categories of people for our purpose. The `JobRoleInterest` column describes for every participant the role(s) they'd be interested in working in. If a participant is interested in working in a certain domain, it means that they're also interested in learning about that domain. So let's take a look at the frequency distribution table of this column and determine whether the data we have is relevant. # In[2]: # Frequency distribution table for 'JobRoleInterest' fcc['JobRoleInterest'].value_counts(normalize = True) * 100 # The information in the table above is quite granular, but from a quick scan it looks like: # # * A lot of people are interested in web development (full-stack _web development_, front-end _web development_ and back-end _web development_). # * A few people (1.7%) are interested in mobile development. # * Not too many people are interested in domains other than web and mobile development. # # It's also interesting to note that many respondents are interested in more than one subject. It'd be useful to get a better picture of how many people are interested in a single subject and how many have mixed interests. Consequently, in the next code block, we'll: # # - Split each string in the `JobRoleInterest` column to find the number of options for each participant. # - We'll first drop the null values because we can't split `Nan` values. # - Generate a frequency table for the variable describing the number of options. # In[3]: # Split each string in the 'JobRoleInterest' column interests_no_nulls = fcc['JobRoleInterest'].dropna() splitted_interests = interests_no_nulls.str.split(',') # Frequency table for the var describing the number of options n_of_options = splitted_interests.apply(lambda x: len(x)) # x is a list of job options n_of_options.value_counts(normalize = True).sort_index() * 100 # It turns out that only 31.7% of the participants have a clear idea about what programming niche they'd like to work in, while the vast majority of students have mixed interests. But given that we offer courses on various subjects, the fact that new coders have mixed interest might be actually good for us. # # The focus of our courses is on web and mobile development, so let's find out how many respondents chose at least one of these two options. # In[4]: # Frequency table web_or_mobile = interests_no_nulls.str.contains( 'Web Developer|Mobile Developer') # returns an array of booleans freq_table = web_or_mobile.value_counts(normalize = True) * 100 print(freq_table) # Graph for the frequency table above get_ipython().run_line_magic('matplotlib', 'inline') import matplotlib.pyplot as plt plt.style.use('fivethirtyeight') freq_table.plot.bar() plt.title('Most Participants are Interested in \nWeb or Mobile Development', y = 1.08) # y pads the title upward plt.ylabel('Percentage', fontsize = 12) plt.xticks([0,1],['Web or mobile\ndevelopment', 'Other subject'], rotation = 0) # the initial xtick labels were True and False plt.ylim([0,100]) plt.show() # It turns out that most people in this survey (roughly 86%) are interested in either web or mobile development. These figures offer us a strong reason to consider this sample representative for our population of interest. We want to advertise our courses to people interested in all sorts of programming niches but mostly web and mobile development. # # Now we need to figure out what are the best markets to invest money in for advertising our courses. We'd like to know: # # * Where are these new coders located. # * What are the locations with the greatest number of new coders. # * How much money new coders are willing to spend on learning. # # # New Coders - Locations and Densities # # Let's begin with finding out where these new coders are located, and what are the densities (how many new coders there are) for each location. This should be a good start for finding out the best two markets to run our ads campaign in. # # The data set provides information about the location of each participant at a country level. We can think of each country as an individual market, so we can frame our goal as finding the two best countries to advertise in. # # We can start by examining the frequency distribution table of the `CountryLive` variable, which describes what country each participant lives in (not their origin country). We'll only consider those participants who answered what role(s) they're interested in, to make sure we work with a representative sample. # In[5]: # Isolate the participants that answered what role they'd be interested in fcc_good = fcc[fcc['JobRoleInterest'].notnull()].copy() # Frequency tables with absolute and relative frequencies absolute_frequencies = fcc_good['CountryLive'].value_counts() relative_frequencies = fcc_good['CountryLive'].value_counts(normalize = True) * 100 # Display the frequency tables in a more readable format pd.DataFrame(data = {'Absolute frequency': absolute_frequencies, 'Percentage': relative_frequencies} ) # 45.7% of our potential customers are located in the US, and this definitely seems like the most interesting market. India has the second customer density, but it's just 7.7%, which is not too far from the United Kingdom (4.6%) or Canada (3.8%). # # This is useful information, but we need to go more in depth than this and figure out how much money people are actually willing to spend on learning. Advertising in high-density markets where most people are only willing to learn for free is extremely unlikely to be profitable for us. # # # Spending Money for Learning # # The `MoneyForLearning` column describes in American dollars the amount of money spent by participants from the moment they started coding until the moment they completed the survey. Our company sells subscriptions at a price of \$59 per month, and for this reason we're interested in finding out how much money each student spends per month. # # We'll narrow down our analysis to only four countries: the US, India, the United Kingdom, and Canada. We do this for two reasons: # # * These are the countries having the highest frequency in the frequency table above, which means we have a decent amount of data for each. # * Our courses are written in English, and English is an official language in all these four countries. The more people know English, the better our chances to target the right people with our ads. # # Let's start with creating a new column that describes the amount of money a student has spent per month so far. To do that, we'll need to divide the `MoneyForLearning` column to the `MonthsProgramming` column. The problem is that some students answered that they have been learning to code for 0 months (it might be that they have just started). To avoid dividing by 0, we'll replace 0 with 1 in the `MonthsProgramming` column. # In[6]: # Replace 0s with 1s to avoid division by 0 fcc_good['MonthsProgramming'].replace(0,1, inplace = True) # New column for the amount of money each student spends each month fcc_good['money_per_month'] = fcc_good['MoneyForLearning'] / fcc_good['MonthsProgramming'] fcc_good['money_per_month'].isnull().sum() # Let's keep only the rows that don't have null values for the `money_per_month` column. # In[7]: # Keep only the rows with non-nulls in the `money_per_month` column fcc_good = fcc_good[fcc_good['money_per_month'].notnull()] # We want to group the data by country, and then measure the average amount of money that students spend per month in each country. First, let's remove the rows having null values for the `CountryLive` column, and check out if we still have enough data for the four countries that interest us. # In[8]: # Remove the rows with null values in 'CountryLive' fcc_good = fcc_good[fcc_good['CountryLive'].notnull()] # Frequency table to check if we still have enough data fcc_good['CountryLive'].value_counts().head() # This should be enough, so let's compute the average value spent per month in each country by a student. We'll compute the average using the mean. # In[9]: # Mean sum of money spent by students each month countries_mean = fcc_good.groupby('CountryLive').mean() countries_mean['money_per_month'][['United States of America', 'India', 'United Kingdom', 'Canada']] # The results for the United Kingdom and Canada are a bit surprising relative to the values we see for India. If we considered a few socio-economical metrics (like [GDP per capita](https://bit.ly/2I3cukh)), we'd intuitively expect people in the UK and Canada to spend more on learning than people in India. # # It might be that we don't have have enough representative data for the United Kingdom and Canada, or we have some outliers (maybe coming from wrong survey answers) making the mean too large for India, or too low for the UK and Canada. Or it might be that the results are correct. # # # Dealing with Extreme Outliers # # Let's use box plots to visualize the distribution of the `money_per_month` variable for each country. # In[10]: # Isolate only the countries of interest only_4 = fcc_good[fcc_good['CountryLive'].str.contains( 'United States of America|India|United Kingdom|Canada')] # Box plots to visualize distributions import seaborn as sns sns.boxplot(y = 'money_per_month', x = 'CountryLive', data = only_4) plt.title('Money Spent Per Month Per Country\n(Distributions)', fontsize = 16) plt.ylabel('Money per month (US dollars)') plt.xlabel('Country') plt.xticks(range(4), ['US', 'UK', 'India', 'Canada']) # avoids tick labels overlap plt.show() # It's hard to see on the plot above if there's anything wrong with the data for the United Kingdom, India, or Canada, but we can see immediately that there's something really off for the US: two persons spend each month \$50000 or more for learning. This is not impossible, but it seems extremely unlikely, so we'll remove every value that goes over \$20,000 per month. # In[11]: # Isolate only those participants who spend less than 10000 per month fcc_good = fcc_good[fcc_good['money_per_month'] < 20000] # Now let's recompute the mean values and plot the box plots again. # In[12]: # Recompute mean sum of money spent by students each month countries_mean = fcc_good.groupby('CountryLive').mean() countries_mean['money_per_month'][['United States of America', 'India', 'United Kingdom', 'Canada']] # In[13]: # Isolate again the countries of interest only_4 = fcc_good[fcc_good['CountryLive'].str.contains( 'United States of America|India|United Kingdom|Canada')] # Box plots to visualize distributions sns.boxplot(y = 'money_per_month', x = 'CountryLive', data = only_4) plt.title('Money Spent Per Month Per Country\n(Distributions)', fontsize = 16) plt.ylabel('Money per month (US dollars)') plt.xlabel('Country') plt.xticks(range(4), ['US', 'UK', 'India', 'Canada']) # avoids tick labels overlap plt.show() # We can see a few extreme outliers for India (values over \$2500 per month), but it's unclear whether this is good data or not. Maybe these persons attended several bootcamps, which tend to be very expensive. Let's examine these two data points to see if we can find anything relevant. # In[14]: # Inspect the extreme outliers for India india_outliers = only_4[ (only_4['CountryLive'] == 'India') & (only_4['money_per_month'] >= 2500)] india_outliers # It seems that neither participant attended a bootcamp. Overall, it's really hard to figure out from the data whether these persons really spent that much money with learning. The actual question of the survey was _"Aside from university tuition, about how much money have you spent on learning to code so far (in US dollars)?"_, so they might have misunderstood and thought university tuition is included. It seems safer to remove these two rows. # In[15]: # Remove the outliers for India only_4 = only_4.drop(india_outliers.index) # using the row labels # Looking back at the box plot above, we can also see more extreme outliers for the US (values over \$6000 per month). Let's examine these participants in more detail. # In[16]: # Examine the extreme outliers for the US us_outliers = only_4[ (only_4['CountryLive'] == 'United States of America') & (only_4['money_per_month'] >= 6000)] us_outliers # Out of these 11 extreme outliers, six people attended bootcamps, which justify the large sums of money spent on learning. For the other five, it's hard to figure out from the data where they could have spent that much money on learning. Consequently, we'll remove those rows where participants reported thay they spend \$6000 each month, but they have never attended a bootcamp. # # Also, the data shows that eight respondents had been programming for no more than three months when they completed the survey. They most likely paid a large sum of money for a bootcamp that was going to last for several months, so the amount of money spent per month is unrealistic and should be significantly lower (because they probably didn't spend anything for the next couple of months after the survey). As a consequence, we'll remove every these eight outliers. # # In the next code block, we'll remove respondents that: # # - Didn't attend bootcamps. # - Had been programming for three months or less when at the time they completed the survey. # In[17]: # Remove the respondents who didn't attendent a bootcamp no_bootcamp = only_4[ (only_4['CountryLive'] == 'United States of America') & (only_4['money_per_month'] >= 6000) & (only_4['AttendedBootcamp'] == 0) ] only_4 = only_4.drop(no_bootcamp.index) # Remove the respondents that had been programming for less than 3 months less_than_3_months = only_4[ (only_4['CountryLive'] == 'United States of America') & (only_4['money_per_month'] >= 6000) & (only_4['MonthsProgramming'] <= 3) ] only_4 = only_4.drop(less_than_3_months.index) # Looking again at the last box plot above, we can also see an extreme outlier for Canada — a person who spends roughly \$5000 per month. Let's examine this person in more depth. # In[18]: # Examine the extreme outliers for Canada canada_outliers = only_4[ (only_4['CountryLive'] == 'Canada') & (only_4['money_per_month'] > 4500)] canada_outliers # Here, the situation is similar to some of the US respondents — this participant had been programming for no more than two months when he completed the survey. He seems to have paid a large sum of money in the beginning to enroll in a bootcamp, and then he probably didn't spend anything for the next couple of months after the survey. We'll take the same approach here as for the US and remove this outlier. # In[19]: # Remove the extreme outliers for Canada only_4 = only_4.drop(canada_outliers.index) # Let's recompute the mean values and generate the final box plots. # In[20]: # Recompute mean sum of money spent by students each month only_4.groupby('CountryLive').mean()['money_per_month'] # In[21]: # Visualize the distributions again sns.boxplot(y = 'money_per_month', x = 'CountryLive', data = only_4) plt.title('Money Spent Per Month Per Country\n(Distributions)', fontsize = 16) plt.ylabel('Money per month (US dollars)') plt.xlabel('Country') plt.xticks(range(4), ['US', 'UK', 'India', 'Canada']) # avoids tick labels overlap plt.show() # ## Choosing the Two Best Markets to Advertise in # # Obviously, one country we should advertise in is the US. Lots of new coders live there and they are willing to pay a good amount of money each month (roughly \$143). # # We sell subscriptions at a price of \$59 per month, and Canada seems to be the best second choice because people there are willing to pay roughly \$93 per month, compared to India (\$66) and the United Kingdom (\$45). # # The data suggests strongly that we shouldn't advertise in the UK, but let's take a second look at India before deciding to choose Canada as our second best choice: # # * $59 doesn't seem like an expensive sum for people in India since they spend on average \$66 each month. # * We have almost twice as more potential customers in India than we have in Canada: # In[22]: # Frequency table for the 'CountryLive' column only_4['CountryLive'].value_counts(normalize = True) * 100 # So it's not crystal clear what to choose between Canada and India. Although it seems more tempting to choose Canada, there are good chances that India might actually be a better choice because of the large number of potential customers. # # At this point, it seems that we have several options: # # 1. Advertise in the US, India, and Canada by splitting the advertisement budget in various combinations: # - 60% for the US, 25% for India, 15% for Canada. # - 50% for the US, 30% for India, 20% for Canada; etc. # # 2. Advertise only in the US and India, or the US and Canada. Again, it makes sense to split the advertisement budget unequally. For instance: # - 70% for the US, and 30% for India. # - 65% for the US, and 35% for Canada; etc. # # 3. Advertise only in the US. # # At this point, it's probably best to send our analysis to the marketing team and let them use their domain knowledge to decide. They might want to do some extra surveys in India and Canada and then get back to us for analyzing the new survey data. # # # Conclusion # # In this project, we analyzed survey data from new coders to find the best two markets to advertise in. The only solid conclusion we reached is that the US would be a good market to advertise in. # # For the second best market, it wasn't clear-cut what to choose between India and Canada. We decided to send the results to the marketing team so they can use their domain knowledge to take the best decision.