Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如果存在';没有这个术语的数据吗?_Python_Python 3.x_Pandas_Google Trends - Fatal编程技术网

Python 如果存在';没有这个术语的数据吗?

Python 如果存在';没有这个术语的数据吗?,python,python-3.x,pandas,google-trends,Python,Python 3.x,Pandas,Google Trends,以下脚本有问题: import pandas as pd from pytrends.request import TrendReq pytrend = TrendReq(hl='en-AU', tz=360) keywords = pd.read_csv("keywordlist.txt") pytrend.build_payload( kw_list=keywords, cat=0, geo='AU', gprop='') data

以下脚本有问题:

import pandas as pd
from pytrends.request import TrendReq
pytrend = TrendReq(hl='en-AU', tz=360)
keywords = pd.read_csv("keywordlist.txt")
pytrend.build_payload(
     kw_list=keywords,
     cat=0,
     geo='AU',
     gprop='')
data = pytrend.interest_over_time()
data.to_csv('KeywordList.csv', encoding='utf_8_sig')
如果GoogleTrends没有特定搜索查询的任何数据,脚本将抛出一个错误。当然,如果有数据,效果很好

我遇到的问题是在使用列表(“keywordlist.txt”)时,脚本会生成一个空的.csv,尽管我知道一些搜索词确实有谷歌趋势数据

我是否可以进行更改,以便如果没有特定搜索词的数据,该行将被跳过,并移到下一行


理想的结果是一个.csv文件,其中只包含包含数据的搜索词(及其相关的兴趣指标)。

您的“keywordlist.txt”被读取为数据框“keyword”有什么原因吗?我假设
kwu list
应该是一个列表,而不是一个数据帧。你能显示你的“keywordlist.txt”文件吗?