KeyError: «Передача списка лайков в .lo c или [] с отсутствующими метками больше не поддерживается в файле json - PullRequest
0 голосов
/ 26 марта 2020
{'meta': {'code': 200, 'requestId': '5e7c703bb9a389001b7d1e8c'},
 'response': {'suggestedFilters': {'header': 'Tap to show:',
   'filters': [{'name': 'Open now', 'key': 'openNow'}]},
  'headerLocation': 'Lagos',
  'headerFullLocation': 'Lagos',
  'headerLocationGranularity': 'city',
  'totalResults': 39,
  'suggestedBounds': {'ne': {'lat': 6.655478745000045,
    'lng': 3.355524537252914},
   'sw': {'lat': 6.565478654999954, 'lng': 3.2650912627470863}},
  'groups': [{'type': 'Recommended Places',
    'name': 'recommended',
    'items': [{'reasons': {'count': 0,
       'items': [{'summary': 'This spot is popular',
         'type': 'general',
         'reasonName': 'globalInteractionReason'}]},
      'venue': {'id': '502806dce4b0f23b021f3b77',
       'name': 'KFC',
       'location': {'lat': 6.604589745106469,
        'lng': 3.3089358809010045,
        'labeledLatLngs': [{'label': 'display',
          'lat': 6.604589745106469,
          'lng': 3.3089358809010045}],
        'distance': 672,
        'cc': 'NG',
        'city': 'Egbeda',
        'state': 'Lagos',
        'country': 'Nigeria',
        'formattedAddress': ['Egbeda', 'Lagos', 'Nigeria']},
       'categories': [{'id': '4bf58dd8d48988d16e941735',
         'name': 'Fast Food Restaurant',
         'pluralName': 'Fast Food Restaurants',
         'shortName': 'Fast Food',
         'icon': {'prefix': 'https://ss3.4sqi.net/img/categories_v2/food/fastfood_',
          'suffix': '.png'},
         'primary': True}],
       'photos': {'count': 0, 'groups': []}},
      'referralId': 'e-0-502806dce4b0f23b021f3b77-0'},

Это часть моего файла о так называемых «результатах»

Я тогда

def getCAT(row):
    try:
        categories_list=row['categories']
    except:
        categories_list=row['venue.categories']

    if len(categories_list)==0:
        return None
    else:
        return categories_list[0]['name']

venues = results ['response'] ['groups'] [0 ] ['items']

near_venues = pd.json_normalize (venues)

Filter_cols = ['venue.name', 'venue.catergories', 'venue.location.lat', ' venue.location.lng ']

near_venues = near_venues.loc [:, Filter_cols]

near_venues [' venue.categories '] = near_venues.apply (getCAT, axis = 1)

near_venues.columns = [col.split (".") [- 1] для col в near_venues.columns]

near_venues.head ()

Я получаю KeyError: «Передача списка лайков в .lo c или [] с отсутствующими метками больше не поддерживается в файле json.

, если я закомментирую эту часть, она работает хорошо, но с ограниченным результатом. Что я делаю не так?

1 Ответ

0 голосов
/ 27 марта 2020

pandas .DataFrame.lo c

свойство DataFrame.lo c

Доступ к группе строк и столбцов по меткам или логическим значениям массив.

Попробуйте удалить venue. из строки iltered_cols=['venue.name', 'venue.catergories', 'venue.location.lat', 'venue.location.lng']

...