Google Trends¶
Google Trends has data going back to January 1, 2004 about the frequencies of search terms, which can be imported into a pandas DataFrame using the pytrends library.
We can use various methods such as interest_over_time()
or interest_by_region
.
#install the pytrends package
!pip install --user pytrends
Requirement already satisfied: pytrends in /home/mikel/.local/lib/python3.7/site-packages (4.7.3)
Requirement already satisfied: lxml in /home/mikel/anaconda3/lib/python3.7/site-packages (from pytrends) (4.4.1)
Requirement already satisfied: pandas>=0.25 in /home/mikel/anaconda3/lib/python3.7/site-packages (from pytrends) (0.25.1)
Requirement already satisfied: requests in /home/mikel/anaconda3/lib/python3.7/site-packages (from pytrends) (2.22.0)
Requirement already satisfied: python-dateutil>=2.6.1 in /home/mikel/anaconda3/lib/python3.7/site-packages (from pandas>=0.25->pytrends) (2.8.0)
Requirement already satisfied: numpy>=1.13.3 in /home/mikel/anaconda3/lib/python3.7/site-packages (from pandas>=0.25->pytrends) (1.17.2)
Requirement already satisfied: pytz>=2017.2 in /home/mikel/anaconda3/lib/python3.7/site-packages (from pandas>=0.25->pytrends) (2019.3)
Requirement already satisfied: idna<2.9,>=2.5 in /home/mikel/anaconda3/lib/python3.7/site-packages (from requests->pytrends) (2.8)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /home/mikel/anaconda3/lib/python3.7/site-packages (from requests->pytrends) (1.24.2)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /home/mikel/anaconda3/lib/python3.7/site-packages (from requests->pytrends) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in /home/mikel/anaconda3/lib/python3.7/site-packages (from requests->pytrends) (2019.9.11)
Requirement already satisfied: six>=1.5 in /home/mikel/anaconda3/lib/python3.7/site-packages (from python-dateutil>=2.6.1->pandas>=0.25->pytrends) (1.12.0)
from pytrends.request import TrendReq
import pandas as pd
pytrend = TrendReq()
pytrend.build_payload(kw_list=['Mars', 'Venus'])
df = pytrend.interest_over_time()
df
Mars | Venus | isPartial | |
---|---|---|---|
date | |||
2015-09-27 | 100 | 17 | False |
2015-10-04 | 42 | 15 | False |
2015-10-11 | 39 | 17 | False |
2015-10-18 | 37 | 15 | False |
2015-10-25 | 36 | 15 | False |
... | ... | ... | ... |
2020-08-16 | 21 | 15 | False |
2020-08-23 | 23 | 14 | False |
2020-08-30 | 22 | 16 | False |
2020-09-06 | 27 | 15 | False |
2020-09-13 | 26 | 36 | True |
260 rows × 3 columns