Google Trends (Timeseries): Introduction

Google Trends gives us an estimate of search volume. Let's explore if search popularity relates to other kinds of data. Perhaps there are patterns in Google's search volume and the price of Bitcoin or a hot stock like Tesla. Perhaps search volume for the term "Unemployment Benefits" can tell us something about the actual unemployment rate?

Data Sources:

Import Statements

Read the Data

Download and add the .csv files to the same folder as your notebook.

Data Exploration

Tesla

Challenge:

Unemployment Data

Bitcoin

Data Cleaning

Check for Missing Values

Challenge: Are there any missing values in any of the dataframes? If so, which row/rows have missing values? How many missing values are there?

Challenge: Remove any missing values that you found.

Convert Strings to DateTime Objects

Challenge: Check the data type of the entries in the DataFrame MONTH or DATE columns. Convert any strings in to Datetime objects. Do this for all 4 DataFrames. Double check if your type conversion was successful.

Converting from Daily to Monthly Data

Pandas .resample() documentation

Data Visualisation

Notebook Formatting & Style Helpers

Tesla Stock Price v.s. Search Volume

Challenge: Plot the Tesla stock price against the Tesla search volume using a line chart and two different axes. Label one axis 'TSLA Stock Price' and the other 'Search Trend'.

Challenge: Add colours to style the chart. This will help differentiate the two lines and the axis labels. Try using one of the blue colour names for the search volume and a HEX code for a red colour for the stock price.

Hint: you can colour both the axis labels and the lines on the chart using keyword arguments (kwargs).

Challenge: Make the chart larger and easier to read.

  1. Increase the figure size (e.g., to 14 by 8).
  2. Increase the font sizes for the labels and the ticks on the x-axis to 14.
  3. Rotate the text on the x-axis by 45 degrees.
  4. Make the lines on the chart thicker.
  5. Add a title that reads 'Tesla Web Search vs Price'
  6. Keep the chart looking sharp by changing the dots-per-inch or DPI value.
  7. Set minimum and maximum values for the y and x axis. Hint: check out methods like set_xlim().
  8. Finally use plt.show() to display the chart below the cell instead of relying on the automatic notebook output.

How to add tick formatting for dates on the x-axis.

Bitcoin (BTC) Price v.s. Search Volume

Challenge: Create the same chart for the Bitcoin Prices vs. Search volumes.

  1. Modify the chart title to read 'Bitcoin News Search vs Resampled Price'
  2. Change the y-axis label to 'BTC Price'
  3. Change the y- and x-axis limits to improve the appearance
  4. Investigate the linestyles to make the BTC price a dashed line
  5. Investigate the marker types to make the search datapoints little circles
  6. Were big increases in searches for Bitcoin accompanied by big increases in the price?

Unemployement Benefits Search vs. Actual Unemployment in the U.S.

Challenge Plot the search for "unemployment benefits" against the unemployment rate.

  1. Change the title to: Monthly Search of "Unemployment Benefits" in the U.S. vs the U/E Rate
  2. Change the y-axis label to: FRED U/E Rate
  3. Change the axis limits
  4. Add a grey grid to the chart to better see the years and the U/E rate values. Use dashes for the line style
  5. Can you discern any seasonality in the searches? Is there a pattern?

Challenge: Calculate the 3-month or 6-month rolling average for the web searches. Plot the 6-month rolling average search data against the actual unemployment. What do you see in the chart? Which line moves first?

Including 2020 in Unemployment Charts

Challenge: Read the data in the 'UE Benefits Search vs UE Rate 2004-20.csv' into a DataFrame. Convert the MONTH column to Pandas Datetime objects and then plot the chart. What do you see?