【ChatGPT】搜索趋势分析
为了分析 ChatGPT 在过去一年的流行趋势,我们可以查看 Google Trends 的数据
安装依赖pytrends
pip install pytrends
运行以下 Python 脚本
import pandas as pd
import matplotlib.pyplot as plt
from pytrends.request import TrendReq# Set up Google Trends API
pytrends = TrendReq(hl='en-US', tz=360)# Define the keyword and timeframe
kw_list = ["ChatGPT"]
pytrends.build_payload(kw_list, timeframe='today 12-m') # last 12 months# Fetch the interest over time
interest_over_time_df = pytrends.interest_over_time()# Ensure data is available and clean
if not interest_over_time_df.empty:# Plotting the trendplt.figure(figsize=(12, 6))plt.plot(interest_over_time_df.index, interest_over_time_df['ChatGPT'], color='blue', label='ChatGPT')plt.title("Google Search Trend for 'ChatGPT' Over the Last Year")plt.xlabel("Date")plt.ylabel("Search Interest")plt.legend()plt.grid(True)plt.show()
else:print("No data available for the specified search term and timeframe.")
输出
代理配置
# Define proxies as a list with at least one valid proxy
proxies_list = ['https://your_proxy_here:port', # Replace with actual proxy address
]# Ensure pytrends initializes with a non-empty proxy list
if proxies_list:pytrends = TrendReq(hl='en-US', tz=360, proxies=proxies_list)
else:raise ValueError("Proxies list is empty. Add at least one proxy.")