Skip to content

Instantly share code, notes, and snippets.

@Abhayparashar31
Created December 16, 2024 04:47
Show Gist options
  • Save Abhayparashar31/9acdb9efffdaab6c84ccdbbfb525a888 to your computer and use it in GitHub Desktop.
Save Abhayparashar31/9acdb9efffdaab6c84ccdbbfb525a888 to your computer and use it in GitHub Desktop.
#!pip install pytrends
from pytrends.request import TrendReq
import matplotlib.pyplot as plt
# Function to get Google Trends data
def get_google_trends_data(keywords, timeframe='today 3-m', geo='US'):
pytrends = TrendReq(hl='en-US', tz=360)
# Build the payload
pytrends.build_payload(keywords, cat=0, timeframe=timeframe, geo=geo, gprop='')
# Get interest over time
interest_over_time_df = pytrends.interest_over_time()
return interest_over_time_df
# Example keywords related to your article
STOCKS = ["AMZN", "MSFT", "NVDA", "AAPL", "GOOG"]
# Fetch Google Trends data
trends_data = get_google_trends_data(STOCKS)
# Plot the data
plt.figure(figsize=(20, 12))
trends_data.plot(title='Google Trends for STOCKS')
plt.xlabel('Date')
plt.ylabel('Interest Over Time')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment