You are a product manager for a fitness studio and are interested in understanding the current demand for digital fitness classes. You plan to conduct a market analysis in Python to gauge demand and identify potential areas for growth of digital products and services.
The Data
You are provided with a number of CSV files in the "Files/data" folder, which offer international and national-level data on Google Trends keyword searches related to fitness and related products.
workout.csv
| Column | Description |
|---|---|
'month' | Month when the data was measured. |
'workout_worldwide' | Index representing the popularity of the keyword 'workout', on a scale of 0 to 100. |
three_keywords.csv
| Column | Description |
|---|---|
'month' | Month when the data was measured. |
'home_workout_worldwide' | Index representing the popularity of the keyword 'home workout', on a scale of 0 to 100. |
'gym_workout_worldwide' | Index representing the popularity of the keyword 'gym workout', on a scale of 0 to 100. |
'home_gym_worldwide' | Index representing the popularity of the keyword 'home gym', on a scale of 0 to 100. |
workout_geo.csv
| Column | Description |
|---|---|
'country' | Country where the data was measured. |
'workout_2018_2023' | Index representing the popularity of the keyword 'workout' during the 5 year period. |
three_keywords_geo.csv
| Column | Description |
|---|---|
'country' | Country where the data was measured. |
'home_workout_2018_2023' | Index representing the popularity of the keyword 'home workout' during the 5 year period. |
'gym_workout_2018_2023' | Index representing the popularity of the keyword 'gym workout' during the 5 year period. |
'home_gym_2018_2023' | Index representing the popularity of the keyword 'home gym' during the 5 year period. |
# Import the necessary libraries
import pandas as pd
import matplotlib.pyplot as plt
import os# Start coding here
workout_df = pd.read_csv("data/workout.csv")
three_kw_df = pd.read_csv("data/three_keywords.csv")
workout_geo_df = pd.read_csv("data/workout_geo.csv")
three_kw_geo_df = pd.read_csv("data/three_keywords_geo.csv")
print(workout_df.head())
print(three_kw_df.head())
print(workout_geo_df.head())
print(three_kw_geo_df.head())# convert 'month' column in datetime format, extract the year and create a new column with year value.
workout_df['month'] = pd.to_datetime(workout_df['month'])
workout_df['year'] = workout_df['month'].dt.year
# group by year and calculate the sum of number of "workout" searches for each year
workout_group_by_year_df = workout_df.groupby('year').sum()
#extract max year from the workout_group_by_year_df DataFrame
max_year = workout_group_by_year_df['workout_worldwide'].idxmax()
# convert max year to string
year_str = str(max_year)
print(year_str)Question 2
# plot the graph for the number of keyword searches against the year, for each key word
plt.plot(three_kw_df["month"], three_kw_df["home_workout_worldwide"], label="Home workout")
plt.plot(three_kw_df["month"], three_kw_df["gym_workout_worldwide"], label="Gym workout")
plt.plot(three_kw_df["month"], three_kw_df["home_gym_worldwide"], label="Home gym")
plt.xticks(rotation=45)
plt.legend()
plt.show()From the plot, we see that: During COVID, "home workout" was the most searched keyword For the most recent time period (2023), 'gym workout' is the most searched keyword
peak_covid = "home workout"
current = "gym workout"Question 3
Questions 3 code produces an error even tho this has been crosschecked w the question's solution. May be due to a faulty DB
grouped_countries = workout_geo_df.groupby('country')['workout_2018_2023'].sum()
print(workout_geo_df.loc['United States'])
print(workout_geo_df.loc["Australia"])
print(workout_geo_df.loc["Japan"])
# print(workout_geo_df.head())
# print(grouped_countries)
top_country = "United States"Question 4
Questions 4 code produces an error even tho this has been crosschecked w the question's solution. May be due to a faulty DB
print(three_kw_geo_df.loc["Philippines", :])
print(three_kw_geo_df.loc["Malaysia", :])
home_workout_geo = "Philippines"