Skip to main content

A Python package to collect and analyze Google Trends data for US states.

Project description

GTUS - Google Trends for US States

The GTUS package is a Python library designed to collect Google Trends data for specified queries across various U.S. states. It provides functionality to handle multiple queries and states efficiently, while adhering to Google Trends API limitations.


Features

  • Collect trends for one or multiple states.
  • Batch processing of queries to avoid API limits.
  • Adjustable wait time between requests to manage rate limits.
  • Export collected data to Excel and JSON formats.
  • Access data in a consolidated pandas DataFrame for easy analysis.

Installation

To use the GTUS package, ensure you have the required dependencies installed. You can install them using pip:

pip install gtus

This will automatically install all required dependencies, including pytrends, pandas, and aiohttp.


Getting Started

Here's how to start using GTUS to collect Google Trends data.

Importing the Package

To use the GTUS package, import it as follows:

from gtus import GTUS

1. Collect Google Trends Data for US States

Collecting for One State

To collect data for a single state, create an instance of the GTUS class with the desired query and state:

from gtus import GTUS

queries = ["telemedicine", "remote work"]
states = ["TX"]
gtus = GTUS(queries, states, timeframe="2022-01-01 2023-01-01")

# Collect data
gtus.collect_all_trends()

Collecting for Multiple States

To collect data for multiple states, simply provide a list of states:

from gtus import GTUS

queries = ["telemedicine", "remote", "football", "dance"]
states = ["CA", "NY", "TX"]
gtus = GTUS(queries, states, timeframe="2020-01-01 2023-01-01")

# Collect data
gtus.collect_all_trends()

Collecting for All States

If no states are specified, GTUS will automatically collect data for all US states:

queries = ["remote work", "telehealth"]

# Initialize GTUS object
gtus = GTUS(queries=queries, timeframe="2022-01-01 2023-01-01", wait_time=15)

Modifying Wait Time

You can adjust the wait time between requests by specifying the wait_time parameter when creating the GTUS instance. This is useful for managing API rate limits:

gtus = GTUS(queries, states, wait_time=15)  # Set wait time to 15 seconds

Saving Data

Exporting to Excel

To save the collected data to an Excel file, use the export_to_excel method:

gtus.export_to_excel("google_trends_data.xlsx")

Exporting to JSON

To save the collected data to a JSON file, use the export_to_json method:

gtus.export_to_json("google_trends_data.json")

Accessing Data in Python

The data collected can be accessed in a consolidated pandas DataFrame. This allows for easy manipulation and analysis:

df = gtus.create_consolidated_dataframe()
print(df.head())

Example Output

The DataFrame will have the following structure:

date State telemedicine remote work football dance
2021-12-26 CA 72.0 62.0 59.0 68.0
2021-12-26 TX 73.0 59.0 67.0 70.0

Dependencies

  • pandas
  • pytrends
  • aiohttp
  • openpyxl

Contributing

Contributions are welcome! Please submit issues or pull requests via GitHub.


License

This project is licensed under the MIT License. See the LICENSE file for more information.


Start exploring Google Trends data with GTUS today!

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

gtus-0.0.1.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gtus-0.0.1-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file gtus-0.0.1.tar.gz.

File metadata

  • Download URL: gtus-0.0.1.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.2

File hashes

Hashes for gtus-0.0.1.tar.gz
Algorithm Hash digest
SHA256 e28201e5db0c3311cb2a1d3c440c6115a243e24537af914e759d2dfd74d0ffae
MD5 09b62327d0e99a66d29efc9a958845d5
BLAKE2b-256 ad52a351f4dbea7c08a14763be409efe2ed0dc757c06b56509b0125273934bf3

See more details on using hashes here.

File details

Details for the file gtus-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: gtus-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.2

File hashes

Hashes for gtus-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ec614da403db2db69b01c7a6b568da60217d5e87a976f135a24a3aa7784fe523
MD5 1b0bff03509d551267a371a0a2a89069
BLAKE2b-256 938b667bbb980f05216214bd52564eb85271ded19f5c97713fc6a7ee060b377f

See more details on using hashes here.

Supported by

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