Skip to main content

Tool To Create Google Trends Index From Keywords

Project description

pytrendex

Code to generate a Google Trends Index

Installation

pip install pytrendex

Trendex

The main thrust of this package is a class Trendex. This class makes an index utilizing Google Trends from keywords.

Parameters

  • kw_list: list The list of keywords that will be searched. If larger than 5, will create benchmark term from the first term in the list.

  • geo: str The country or place the search is conducted in, see Trends documentation.

  • date_start: str, optional The data where the index starts in format: 'yyyy-mm-dd', if none provided, then does it at the cutoff days before the date end.

  • date_end: str, optional The data where the index ends in format: 'yyyy-mm-dd', if none provided, then defaults to current day.

  • frequency: str, optional The frequency of the index. Note that the index always pulls daily data, so collapsing into larger time-frames is done by averages ex-post.

  • gen_index: Binary, optional If true, then go ahead and instantiate class to generate indices. Default is True.

  • plot: boolean, optional If True, and gen_index is True, then it plots index. Default is true.

  • kw_list_split: boolean, optional If True then the max length for kw_list is 20 terms; after that it will split the search by using the "+" option for search terms (which acts as an "or" operator for google trends). Highly recommended to keep load down.

  • benchmark_select: boolean, optional If True then optimally search over timeframe for best benchmark phrase, see documentation for that function for description of how this is done. If False, then the benchmark will be the first term in the kw_list.

  • slowdown: boolean, optional If True then include time.sleep() at key moments to slow down the index. Currently defaults to random intervals of mean 5 or 7 seconds depending on where in the code. Remove this at your own peril (Google lockout).

  • seasonal_adjust: boolean, optional (default = True) If True, then seasonally adjust the series (recommended). Seasonally adjusted trends are always constructed and saved in trends_sa, but this incorporates them into the index that is automatically constructed.

Returns (back to class instance)

  • self.gti: Series (main output) This is the normalized indexes made from the underlying data. It is the main thing returned from this function.

  • self.trends: DataFrame (major output) It is the adjusted and combined series for each term searched. You could use this to plot individual keywords in the index. Will differ from raw_trends_adjusted if frequency is changed from daily.

  • self.trends_sa: DataFrame (major output) These are the trends seasonally adjusted; they are always returned.

  • self.raw_trends_adjusted: Dictionary (minor output) These are the adjusted (using overlapping timeframes) raw results for each term. Index of dictionary corresponds to index of timechunks. Could differ from trends if frequency is changed from daily.

  • self.raw_trends: Dictionary (minor output) These are the unadjusted raw results for each term. Note: Adjustment has still been made by the benchmark term for searches exceeding 5 terms.

  • self.adjustment_factors: Series (minor output) Returns the adjustment factors used on each overlapping segment. The adjustment is [term]_1/[term_2] * segment_2

Example

A use case example is provided here:

from pytrendex import Trendex

kw_list = ['Obama','Biden','Clinton','Warren','Trump','Bernie']
geo = 'US'
date_start = '2018-01-01'
frequency = 'weekly'

## Generating the indexes in two different ways
result = Trendex(kw_list=kw_list, geo=geo,
                  plot=False, date_start=date_start, frequency=frequency)

# A smaller index, here we create it in two steps (date start and end and frequency auto selected)
result2 = Trendex(['Obama','Trump'],geo='US',gen_index=False)
result2 = result2.make_index(plot=False)

## Analyzing the results

result.gti.plot() # creates a matplotlib plot of the index for us to look at
result2.trends_sa.plot() # plots the adjusted individual terms that make up the index

result.gti.to_csv('file.csv') # saves the index as a csv file

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytrendex-5.0.0.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

pytrendex-5.0.0-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

Details for the file pytrendex-5.0.0.tar.gz.

File metadata

  • Download URL: pytrendex-5.0.0.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0.post20200309 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.4

File hashes

Hashes for pytrendex-5.0.0.tar.gz
Algorithm Hash digest
SHA256 d9bd7cc54552ac78a5e04d5698924b3a362dcabc7d8492a1716be90b457a9325
MD5 10470d5dfd3a9217a17164e6afcde0d1
BLAKE2b-256 0820ea8e73a96592d1074835dbf09ab7f8075d67b629004098191b3d4842559e

See more details on using hashes here.

File details

Details for the file pytrendex-5.0.0-py3-none-any.whl.

File metadata

  • Download URL: pytrendex-5.0.0-py3-none-any.whl
  • Upload date:
  • Size: 22.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0.post20200309 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.4

File hashes

Hashes for pytrendex-5.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bb94a8f3a8f1013b9d28dd5fe31a850de508093319ddb91027a8804b96445b7e
MD5 49ebc4126081cb1b0f77266d65b5f659
BLAKE2b-256 10df00836a8a101e0839b40e4dff14d987070bcbc417694f482187b086c0897b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page