当我在笔记本上运行这个Python代码时,它返回空表。我得到了这个错误我怎样才能克服这个错误?

当我在笔记本上运行这个Python代码时,它返回空表。我得到了这个错误我怎样才能克服这个错误?,python,dataframe,xpath,html-table,append,Python,Dataframe,Xpath,Html Table,Append,这里是错误消息,它并没有解释代码的错误,我得到的错误类型是KeyError venues = results['response']['groups'][0]['items'] SGnearby_venues = json_normalize(venues) # flatten JSON # filter columns filtered_columns = ['venue.name', 'venue.categories', 'venue.location.lat', 'venue.loca

这里是错误消息,它并没有解释代码的错误,我得到的错误类型是KeyError


venues = results['response']['groups'][0]['items']
SGnearby_venues = json_normalize(venues) # flatten JSON
# filter columns
filtered_columns = ['venue.name', 'venue.categories', 'venue.location.lat', 'venue.location.lng']
SGnearby_venues =SGnearby_venues.loc[:, filtered_columns]
# filter the category for each row
SGnearby_venues['venue.categories'] = SGnearby_venues.apply(get_category_type, axis=1)
# clean columns
SGnearby_venues.columns = [col.split(".")[-1] for col in SGnearby_venues.columns]

SGnearby_venues.shape

---------------------------------------------------------------------------
KeyError回溯(最近一次呼叫最后一次)
在里面
---->1场馆=结果['response']['groups'][0]['items']
2 SGU场馆=json场馆标准化(场馆)#扁平化json
3#过滤柱
4个过滤的_列=['viouse.name'、'viouse.categories'、'viouse.location.lat'、'viouse.location.lng']
5 SGANNERAL_场馆=SGANNERAL_场馆。loc[:,过滤的_列]
KeyError:“组”

有人能帮我跨越这个错误吗?

密钥错误通常意味着密钥不存在。因此,您的
结果['response']
没有键
'groups'

关键错误:“groups”是因为客户端ID、客户端密码、版本,因为它们与我在那里使用的那些都过时了,但在从Foursquare更新后,一切都开始正常运行

请包括(一个片段)结果中的数据如果您需要在不确定结果是否为空(或在您需要的结构中)的情况下运行此代码,则应使用try:和catch the key error是否可以发布至少部分
结果
?以下是部分结果。results=requests.get(url).json()不是这样;这就是变量声明。尝试至少发布
打印(结果)
的部分输出。当你在这里的时候,也可以发布
print(type(results))
的输出。谢谢你,现在我知道keyrerror的意思了
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-23-a945df6402f0> in <module>
----> 1 venues = results['response']['groups'][0]['items']
      2 SGnearby_venues = json_normalize(venues) # flatten JSON
      3 # filter columns
      4 filtered_columns = ['venue.name', 'venue.categories', 'venue.location.lat', 'venue.location.lng']
      5 SGnearby_venues =SGnearby_venues.loc[:, filtered_columns]

KeyError: 'groups'