如何从 API JSON 响应的 'Distance' 属性中获取 'Distance to Nearest ATM'?
How to get 'Distance to Nearest ATM' from 'Distance' attribute of API JSON Response?
我有一个示例 API 响应如下,它具有给定 latitude/Longitude 最近的 ATM。我将为来自 pandas DataFrame 的输入执行此 API,其中有两列用于 Latitude/Longitude。我希望每个位置的输出为 'Distance to the Nearest ATM' 作为原始数据框中的另一列。 JSON 条目有一个属性 'Distance','Distance to the Nearest ATM' 将从中导出。
响应有 20 个最近的 ATM 条目。
以下是 JSON 对我的输入数据帧中的一个位置的响应示例 -
{'results': {'items': [{'averageRating': 0.0,
'category': {'href': 'https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'id': 'atm-bank-exchange',
'system': 'places',
'title': 'ATM/Bank/Exchange',
'type': 'urn:nlp-types:category'},
'chainIds': ['6113'],
'distance': 727,
'having': [],
'href': 'https://places.sit.ls.hereapi.com/places/v1/places/840dr5re-9b94731a418e41848c81389e9bbb5258;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz0w?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'icon': 'https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon',
'id': '840dr5re-9b94731a418e41848c81389e9bbb5258',
'openingHours': {'isOpen': False,
'label': 'Opening hours',
'structured': [{'duration': 'PT09H00M',
'recurrence': 'FREQ:DAILY;BYDAY:MO,TU,WE,TH,FR',
'start': 'T090000'}],
'text': 'Mon-Fri: 09:00 - 18:00'},
'position': [40.71001, -74.00979],
'title': 'Capital One',
'type': 'urn:nlp-types:place',
'vicinity': '176 Broadway<br/>New York, NY 10038'},
{'averageRating': 0.0,
'category': {'href': 'https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'id': 'atm-bank-exchange',
'system': 'places',
'title': 'ATM/Bank/Exchange',
'type': 'urn:nlp-types:category'},
'chainIds': ['2667'],
'distance': 58,
'having': [],
'href': 'https://places.sit.ls.hereapi.com/places/v1/places/840dr5re-ce5c5899421348eab75d05794548b34f;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz0x?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'icon': 'https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon',
'id': '840dr5re-ce5c5899421348eab75d05794548b34f',
'position': [40.70382, -74.01174],
'title': 'TD Bank',
'type': 'urn:nlp-types:place',
'vicinity': '90 Broad St<br/>New York, NY 10004'},
{'averageRating': 0.0,
'category': {'href': 'https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'id': 'atm-bank-exchange',
'system': 'places',
'title': 'ATM/Bank/Exchange',
'type': 'urn:nlp-types:category'},
'distance': 321,
'having': [],
'href': 'https://places.sit.ls.hereapi.com/places/v1/places/840dr5re-efead63cf9b940a7a228c6e8bce1bfab;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz0y?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'icon': 'https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon',
'id': '840dr5re-efead63cf9b940a7a228c6e8bce1bfab',
'position': [40.70526, -74.01422],
'title': 'Berkshire Bank',
'type': 'urn:nlp-types:place',
'vicinity': '5 Broadway<br/>New York, NY 10004'},
{'alternativeNames': [{'language': 'en',
'name': 'TD BANK ATM'}],
'averageRating': 0.0,
'category': {'href': 'https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'id': 'atm-bank-exchange',
'system': 'places',
'title': 'ATM/Bank/Exchange',
'type': 'urn:nlp-types:category'},
'chainIds': ['2667'],
'distance': 457,
'having': [],
'href': 'https://places.sit.ls.hereapi.com/places/v1/places/840dr5re-ff3977a80edd4e80a2ffbb60c5f04dcb;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz0z?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'icon': 'https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon',
'id': '840dr5re-ff3977a80edd4e80a2ffbb60c5f04dcb',
'openingHours': {'isOpen': False,
'label': 'Opening hours',
'structured': [{'duration': 'PT10H30M',
'recurrence': 'FREQ:DAILY;BYDAY:MO,TU,WE,TH,FR',
'start': 'T080000'},
{'duration': 'PT05H00M',
'recurrence': 'FREQ:DAILY;BYDAY:SA',
'start': 'T090000'},
{'duration': 'PT04H00M',
'recurrence': 'FREQ:DAILY;BYDAY:SU',
'start': 'T110000'}],
'text': 'Mon-Fri: 08:00 - '
'18:30<br/>Sat: 09:00 - '
'14:00<br/>Sun: 11:00 - '
'15:00'},
'position': [40.70766, -74.01137],
'title': 'TD Bank',
'type': 'urn:nlp-types:place',
'vicinity': '2 Wall St<br/>New York, NY 10005'},
{'averageRating': 0.0,
'category': {'href': 'https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'id': 'atm-bank-exchange',
'system': 'places',
'title': 'ATM/Bank/Exchange',
'type': 'urn:nlp-types:category'},
'chainIds': ['1165'],
'distance': 522,
'having': [],
'href': 'https://places.sit.ls.hereapi.com/places/v1/places/840dr5re-f5fabc4d9f7141b1a21317c840bacdb9;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz00?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'icon': 'https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon',
'id': '840dr5re-f5fabc4d9f7141b1a21317c840bacdb9',
'openingHours': {'isOpen': False,
'label': 'Opening hours',
'structured': [{'duration': 'PT08H00M',
'recurrence': 'FREQ:DAILY;BYDAY:MO,TU,WE,TH,FR',
'start': 'T090000'}],
'text': 'Mon-Fri: 09:00 - 17:00'},
'position': [40.70823, -74.01056],
'title': 'Citibank',
'type': 'urn:nlp-types:place',
'vicinity': '120 Broadway<br/>New York, NY 10271'},
{'averageRating': 0.0,
'category': {'href': 'https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'id': 'atm-bank-exchange',
'system': 'places',
'title': 'ATM/Bank/Exchange',
'type': 'urn:nlp-types:category'},
'chainIds': ['1290'],
'distance': 1341,
'having': [],
'href': 'https://places.sit.ls.hereapi.com/places/v1/places/840dr5re-35b9d23eef9e44c38a8339285bd801c1;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz01?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'icon': 'https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon',
'id': '840dr5re-35b9d23eef9e44c38a8339285bd801c1',
'position': [40.71535, -74.00782],
'title': 'Bank of America',
'type': 'urn:nlp-types:place',
'vicinity': '168 Church St<br/>New York, NY 10007'},
{'averageRating': 0.0,
'category': {'href': 'https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'id': 'atm-bank-exchange',
'system': 'places',
'title': 'ATM/Bank/Exchange',
'type': 'urn:nlp-types:category'},
'chainIds': ['1106'],
'distance': 567,
'having': [],
'href': 'https://places.sit.ls.hereapi.com/places/v1/places/840dr5re-aa24fe86f42b4815bf757280b552118d;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz02?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'icon': 'https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon',
'id': '840dr5re-aa24fe86f42b4815bf757280b552118d',
'openingHours': {'isOpen': False,
'label': 'Opening hours',
'structured': [{'duration': 'PT08H30M',
'recurrence': 'FREQ:DAILY;BYDAY:MO,TU,WE,TH,FR',
'start': 'T083000'}],
'text': 'Mon-Fri: 08:30 - 17:00'},
'position': [40.708655, -74.01111],
'title': 'HSBC',
'type': 'urn:nlp-types:place',
'vicinity': '117 Broadway<br/>New York, NY 10006'},
{'alternativeNames': [{'language': 'en',
'name': 'Federal Reserve Bank'}],
'averageRating': 0.0,
'category': {'href': 'https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'id': 'atm-bank-exchange',
'system': 'places',
'title': 'ATM/Bank/Exchange',
'type': 'urn:nlp-types:category'},
'distance': 609,
'having': [],
'href': 'https://places.sit.ls.hereapi.com/places/v1/places/840dr5re-ae53f05b1f9e4cb181fc29c2fd8efd40;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz03?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'icon': 'https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon',
'id': '840dr5re-ae53f05b1f9e4cb181fc29c2fd8efd40',
'position': [40.708861, -74.009352],
'title': 'Federal Reserve Bank of New York',
'type': 'urn:nlp-types:place',
'vicinity': '33 Liberty Pl<br/>New York, NY 10038'},
{'averageRating': 0.0,
'category': {'href': 'https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'id': 'atm-bank-exchange',
'system': 'places',
'title': 'ATM/Bank/Exchange',
'type': 'urn:nlp-types:category'},
'distance': 660,
'having': [],
'href': 'https://places.sit.ls.hereapi.com/places/v1/places/840dr5re-2719b12b4b244b8b808dd34014a66e63;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz04?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'icon': 'https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon',
'id': '840dr5re-2719b12b4b244b8b808dd34014a66e63',
'position': [40.70944, -74.01012],
'title': 'Berkshire Bancorp',
'type': 'urn:nlp-types:place',
'vicinity': '160 Broadway<br/>New York, NY 10038'},
{'averageRating': 0.0,
'category': {'href': 'https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'id': 'atm-bank-exchange',
'system': 'places',
'title': 'ATM/Bank/Exchange',
'type': 'urn:nlp-types:category'},
'distance': 1191,
'having': [],
'href': 'https://places.sit.ls.hereapi.com/places/v1/places/840dr5re-00e631bb6a614c74a85060fc21ddb9d7;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz05?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'icon': 'https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon',
'id': '840dr5re-00e631bb6a614c74a85060fc21ddb9d7',
'openingHours': {'isOpen': True,
'label': 'Opening hours',
'structured': [{'duration': 'PT24H00M',
'recurrence': 'FREQ:DAILY;BYDAY:TU,WE,TH,FR,SA,SU',
'start': 'T000000'}],
'text': 'Tue-Sun: 00:00 - 00:00'},
'position': [40.71392, -74.01469],
'title': 'American Express Company',
'type': 'urn:nlp-types:place',
'vicinity': '200 Vesey St<br/>New York, NY 10281'},
{'averageRating': 0.0,
'category': {'href': 'https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'id': 'atm-bank-exchange',
'system': 'places',
'title': 'ATM/Bank/Exchange',
'type': 'urn:nlp-types:category'},
'chainIds': ['1290'],
'distance': 1204,
'having': [],
'href': 'https://places.sit.ls.hereapi.com/places/v1/places/840dr5re-2692d9fbb3384f33af3d5eddce3fcf73;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz0xMA?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'icon': 'https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon',
'id': '840dr5re-2692d9fbb3384f33af3d5eddce3fcf73',
'openingHours': {'isOpen': False,
'label': 'Opening hours',
'structured': [{'duration': 'PT09H30M',
'recurrence': 'FREQ:DAILY;BYDAY:MO,TU,WE,TH,FR',
'start': 'T083000'}],
'text': 'Mon-Fri: 08:30 - 18:00'},
'position': [40.71386, -74.00676],
'title': 'Bank of America',
'type': 'urn:nlp-types:place',
'vicinity': '261 Broadway<br/>New York, NY 10007'},
{'averageRating': 0.0,
'category': {'href': 'https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'id': 'atm-bank-exchange',
'system': 'places',
'title': 'ATM/Bank/Exchange',
'type': 'urn:nlp-types:category'},
'distance': 1453,
'having': [],
'href': 'https://places.sit.ls.hereapi.com/places/v1/places/8403fv6k-0cf06c8d42f40193e3a9b8084fe4e33d;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz0xMQ?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'icon': 'https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon',
'id': '8403fv6k-0cf06c8d42f40193e3a9b8084fe4e33d',
'position': [40.71551, -74.00421],
'title': 'Justice Federal Credit Union',
'type': 'urn:nlp-types:place',
'vicinity': '26 Federal Plz<br/>New York, NY 10278'},
{'averageRating': 0.0,
'category': {'href': 'https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'id': 'atm-bank-exchange',
'system': 'places',
'title': 'ATM/Bank/Exchange',
'type': 'urn:nlp-types:category'},
'distance': 50,
'having': [],
'href': 'https://places.sit.ls.hereapi.com/places/v1/places/8403fv6k-621152dd2a180b3f25443a0eb5ce68e2;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz0xNg?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'icon': 'https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon',
'id': '8403fv6k-621152dd2a180b3f25443a0eb5ce68e2',
'openingHours': {'isOpen': True,
'label': 'Opening hours',
'structured': [{'duration': 'PT12H00M',
'recurrence': 'FREQ:DAILY;BYDAY:MO,TU,WE,TH,FR,SA',
'start': 'T090000'}],
'text': 'Mon-Sat: 09:00 - 21:00'},
'position': [40.70395, -74.01143],
'title': 'New York Cash Net',
'type': 'urn:nlp-types:place',
'vicinity': '85 Broad St<br/>New York, NY 10004'},
{'averageRating': 0.0,
'category': {'href': 'https://places.sit.ls.hereapi.com/places/v1/categories/places/hospital-health-care-facility?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'id': 'hospital-health-care-facility',
'system': 'places',
'title': 'Hospital or Healthcare Facility',
'type': 'urn:nlp-types:category'},
'distance': 50,
'having': [],
'href': 'https://places.sit.ls.hereapi.com/places/v1/places/8408lxx5-925d315190cb060336acf064d68ea7a7;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz0xNw?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'icon': 'https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/26.icon',
'id': '8408lxx5-925d315190cb060336acf064d68ea7a7',
'openingHours': {'isOpen': False,
'label': 'Opening hours',
'structured': [{'duration': 'PT08H00M',
'recurrence': 'FREQ:DAILY;BYDAY:MO,TU,WE,TH,FR',
'start': 'T090000'}],
'text': 'Mon-Fri: 09:00 - 17:00'},
'position': [40.70395, -74.01143],
'title': 'Life Mod',
'type': 'urn:nlp-types:place',
'vicinity': '85 Broad St<br/>New York, NY 10004'},
{'averageRating': 0.0,
'category': {'href': 'https://places.sit.ls.hereapi.com/places/v1/categories/places/hospital-health-care-facility?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'id': 'hospital-health-care-facility',
'system': 'places',
'title': 'Hospital or Healthcare Facility',
'type': 'urn:nlp-types:category'},
'distance': 50,
'having': [],
'href': 'https://places.sit.ls.hereapi.com/places/v1/places/840dr5re-72136d2caf4d41aca1a2daa21789e10b;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz0xOA?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'icon': 'https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/26.icon',
'id': '840dr5re-72136d2caf4d41aca1a2daa21789e10b',
'openingHours': {'isOpen': False,
'label': 'Opening hours',
'structured': [{'duration': 'PT06H30M',
'recurrence': 'FREQ:DAILY;BYDAY:MO,TU,WE,TH,FR',
'start': 'T070000'}],
'text': 'Mon-Fri: 07:00 - 13:30'},
'position': [40.70395, -74.01143],
'title': 'Symbio Physiotherapy',
'type': 'urn:nlp-types:place',
'vicinity': '85 Broad St<br/>New York, NY 10004'},
{'averageRating': 0.0,
'category': {'href': 'https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'id': 'atm-bank-exchange',
'system': 'places',
'title': 'ATM/Bank/Exchange',
'type': 'urn:nlp-types:category'},
'distance': 50,
'having': [],
'href': 'https://places.sit.ls.hereapi.com/places/v1/places/8408lxx5-158041e5aa340aea0d37533b0914dd91;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz0xOQ?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'icon': 'https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon',
'id': '8408lxx5-158041e5aa340aea0d37533b0914dd91',
'openingHours': {'isOpen': False,
'label': 'Opening hours',
'structured': [{'duration': 'PT12H00M',
'recurrence': 'FREQ:DAILY;BYDAY:MO,TU,WE,TH,FR,SA',
'start': 'T080000'}],
'text': 'Mon-Sat: 08:00 - 20:00'},
'position': [40.70395, -74.01143],
'title': 'Fast Payday Loan',
'type': 'urn:nlp-types:place',
'vicinity': '85 Broad St<br/>New York, NY 10004'}],
'next': 'https://places.sit.ls.hereapi.com/places/v1/discover/explore;context=Y2F0PWF0bS1iYW5rLWV4Y2hhbmdlJTJDaG9zcGl0YWwtaGVhbHRoLWNhcmUtZmFjaWxpdHkmZmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmb2Zmc2V0PTIwJnNpemU9MjA?in=40.703553%2C-74.011152%3Br%3D2000.0&app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg'},
'search': {'context': {'href': 'https://places.sit.ls.hereapi.com/places/v1/places/loc-dmVyc2lvbj0xO3RpdGxlPTYwK1BlYXJsK1N0O2xhdD00MC43MDM1NTM7bG9uPS03NC4wMTExNTI7c3RyZWV0PVBlYXJsK1N0O2hvdXNlPTYwO2NpdHk9TmV3K1lvcms7cG9zdGFsQ29kZT0xMDAwNDtjb3VudHJ5PVVTQTtkaXN0cmljdD1GaW5hbmNpYWwrRGlzdHJpY3Q7c3RhdGVDb2RlPU5ZO2NvdW50eT1OZXcrWW9yaztjYXRlZ29yeUlkPWJ1aWxkaW5nO3NvdXJjZVN5c3RlbT1pbnRlcm5hbA;context=c2VhcmNoQ29udGV4dD0x?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'location': {'address': {'city': 'New York',
'country': 'United States',
'countryCode': 'USA',
'county': 'New York',
'district': 'Financial '
'District',
'house': '60',
'postalCode': '10004',
'stateCode': 'NY',
'street': 'Pearl St',
'text': '60 Pearl St<br/>New '
'York, NY '
'10004<br/>USA'},
'position': [40.703553, -74.011152]},
'type': 'urn:nlp-types:place'}}} ```
使用pandas.json_normalize
data
等于您的样本。
import pandas as pd
df = pd.json_normalize(data['results']['items'])
# extract lat & long from position
df[['lat', 'long']] = pd.DataFrame(df.position.tolist(), index=df.index)
# drop position column
df.drop(columns='position', inplace=True)
# move position x & y to index 3 & 4
col = df.pop('lat')
df.insert(3, col.name, col)
col = df.pop('long')
df.insert(4, col.name, col)
# remove chainIds from list
df = df.explode('chainIds')
print(df.head(3))
averageRating chainIds distance lat long having href icon id title type vicinity category.href category.id category.system category.title category.type openingHours.isOpen openingHours.label openingHours.structured openingHours.text alternativeNames
0.0 6113 727 40.71001 -74.00979 [] https://places.sit.ls.hereapi.com/places/v1/places/840dr5re-9b94731a418e41848c81389e9bbb5258;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz0w?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon 840dr5re-9b94731a418e41848c81389e9bbb5258 Capital One urn:nlp-types:place 176 Broadway<br/>New York, NY 10038 https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg atm-bank-exchange places ATM/Bank/Exchange urn:nlp-types:category False Opening hours [{'duration': 'PT09H00M', 'recurrence': 'FREQ:DAILY;BYDAY:MO,TU,WE,TH,FR', 'start': 'T090000'}] Mon-Fri: 09:00 - 18:00 NaN
0.0 2667 58 40.70382 -74.01174 [] https://places.sit.ls.hereapi.com/places/v1/places/840dr5re-ce5c5899421348eab75d05794548b34f;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz0x?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon 840dr5re-ce5c5899421348eab75d05794548b34f TD Bank urn:nlp-types:place 90 Broad St<br/>New York, NY 10004 https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg atm-bank-exchange places ATM/Bank/Exchange urn:nlp-types:category NaN NaN NaN NaN NaN
0.0 NaN 321 40.70526 -74.01422 [] https://places.sit.ls.hereapi.com/places/v1/places/840dr5re-efead63cf9b940a7a228c6e8bce1bfab;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz0y?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon 840dr5re-efead63cf9b940a7a228c6e8bce1bfab Berkshire Bank urn:nlp-types:place 5 Broadway<br/>New York, NY 10004 https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg atm-bank-exchange places ATM/Bank/Exchange urn:nlp-types:category NaN NaN NaN NaN NaN
只需 distance
和 for-loop
distance
在list
里面,所以你需要遍历每个列表来获取值。
for dist in data['results']['items']:
print(dist.get('distance'))
727
58
321
457
522
1341
567
609
660
1191
1204
1453
50
50
50
50
我有一个示例 API 响应如下,它具有给定 latitude/Longitude 最近的 ATM。我将为来自 pandas DataFrame 的输入执行此 API,其中有两列用于 Latitude/Longitude。我希望每个位置的输出为 'Distance to the Nearest ATM' 作为原始数据框中的另一列。 JSON 条目有一个属性 'Distance','Distance to the Nearest ATM' 将从中导出。 响应有 20 个最近的 ATM 条目。 以下是 JSON 对我的输入数据帧中的一个位置的响应示例 -
{'results': {'items': [{'averageRating': 0.0,
'category': {'href': 'https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'id': 'atm-bank-exchange',
'system': 'places',
'title': 'ATM/Bank/Exchange',
'type': 'urn:nlp-types:category'},
'chainIds': ['6113'],
'distance': 727,
'having': [],
'href': 'https://places.sit.ls.hereapi.com/places/v1/places/840dr5re-9b94731a418e41848c81389e9bbb5258;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz0w?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'icon': 'https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon',
'id': '840dr5re-9b94731a418e41848c81389e9bbb5258',
'openingHours': {'isOpen': False,
'label': 'Opening hours',
'structured': [{'duration': 'PT09H00M',
'recurrence': 'FREQ:DAILY;BYDAY:MO,TU,WE,TH,FR',
'start': 'T090000'}],
'text': 'Mon-Fri: 09:00 - 18:00'},
'position': [40.71001, -74.00979],
'title': 'Capital One',
'type': 'urn:nlp-types:place',
'vicinity': '176 Broadway<br/>New York, NY 10038'},
{'averageRating': 0.0,
'category': {'href': 'https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'id': 'atm-bank-exchange',
'system': 'places',
'title': 'ATM/Bank/Exchange',
'type': 'urn:nlp-types:category'},
'chainIds': ['2667'],
'distance': 58,
'having': [],
'href': 'https://places.sit.ls.hereapi.com/places/v1/places/840dr5re-ce5c5899421348eab75d05794548b34f;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz0x?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'icon': 'https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon',
'id': '840dr5re-ce5c5899421348eab75d05794548b34f',
'position': [40.70382, -74.01174],
'title': 'TD Bank',
'type': 'urn:nlp-types:place',
'vicinity': '90 Broad St<br/>New York, NY 10004'},
{'averageRating': 0.0,
'category': {'href': 'https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'id': 'atm-bank-exchange',
'system': 'places',
'title': 'ATM/Bank/Exchange',
'type': 'urn:nlp-types:category'},
'distance': 321,
'having': [],
'href': 'https://places.sit.ls.hereapi.com/places/v1/places/840dr5re-efead63cf9b940a7a228c6e8bce1bfab;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz0y?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'icon': 'https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon',
'id': '840dr5re-efead63cf9b940a7a228c6e8bce1bfab',
'position': [40.70526, -74.01422],
'title': 'Berkshire Bank',
'type': 'urn:nlp-types:place',
'vicinity': '5 Broadway<br/>New York, NY 10004'},
{'alternativeNames': [{'language': 'en',
'name': 'TD BANK ATM'}],
'averageRating': 0.0,
'category': {'href': 'https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'id': 'atm-bank-exchange',
'system': 'places',
'title': 'ATM/Bank/Exchange',
'type': 'urn:nlp-types:category'},
'chainIds': ['2667'],
'distance': 457,
'having': [],
'href': 'https://places.sit.ls.hereapi.com/places/v1/places/840dr5re-ff3977a80edd4e80a2ffbb60c5f04dcb;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz0z?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'icon': 'https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon',
'id': '840dr5re-ff3977a80edd4e80a2ffbb60c5f04dcb',
'openingHours': {'isOpen': False,
'label': 'Opening hours',
'structured': [{'duration': 'PT10H30M',
'recurrence': 'FREQ:DAILY;BYDAY:MO,TU,WE,TH,FR',
'start': 'T080000'},
{'duration': 'PT05H00M',
'recurrence': 'FREQ:DAILY;BYDAY:SA',
'start': 'T090000'},
{'duration': 'PT04H00M',
'recurrence': 'FREQ:DAILY;BYDAY:SU',
'start': 'T110000'}],
'text': 'Mon-Fri: 08:00 - '
'18:30<br/>Sat: 09:00 - '
'14:00<br/>Sun: 11:00 - '
'15:00'},
'position': [40.70766, -74.01137],
'title': 'TD Bank',
'type': 'urn:nlp-types:place',
'vicinity': '2 Wall St<br/>New York, NY 10005'},
{'averageRating': 0.0,
'category': {'href': 'https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'id': 'atm-bank-exchange',
'system': 'places',
'title': 'ATM/Bank/Exchange',
'type': 'urn:nlp-types:category'},
'chainIds': ['1165'],
'distance': 522,
'having': [],
'href': 'https://places.sit.ls.hereapi.com/places/v1/places/840dr5re-f5fabc4d9f7141b1a21317c840bacdb9;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz00?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'icon': 'https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon',
'id': '840dr5re-f5fabc4d9f7141b1a21317c840bacdb9',
'openingHours': {'isOpen': False,
'label': 'Opening hours',
'structured': [{'duration': 'PT08H00M',
'recurrence': 'FREQ:DAILY;BYDAY:MO,TU,WE,TH,FR',
'start': 'T090000'}],
'text': 'Mon-Fri: 09:00 - 17:00'},
'position': [40.70823, -74.01056],
'title': 'Citibank',
'type': 'urn:nlp-types:place',
'vicinity': '120 Broadway<br/>New York, NY 10271'},
{'averageRating': 0.0,
'category': {'href': 'https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'id': 'atm-bank-exchange',
'system': 'places',
'title': 'ATM/Bank/Exchange',
'type': 'urn:nlp-types:category'},
'chainIds': ['1290'],
'distance': 1341,
'having': [],
'href': 'https://places.sit.ls.hereapi.com/places/v1/places/840dr5re-35b9d23eef9e44c38a8339285bd801c1;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz01?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'icon': 'https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon',
'id': '840dr5re-35b9d23eef9e44c38a8339285bd801c1',
'position': [40.71535, -74.00782],
'title': 'Bank of America',
'type': 'urn:nlp-types:place',
'vicinity': '168 Church St<br/>New York, NY 10007'},
{'averageRating': 0.0,
'category': {'href': 'https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'id': 'atm-bank-exchange',
'system': 'places',
'title': 'ATM/Bank/Exchange',
'type': 'urn:nlp-types:category'},
'chainIds': ['1106'],
'distance': 567,
'having': [],
'href': 'https://places.sit.ls.hereapi.com/places/v1/places/840dr5re-aa24fe86f42b4815bf757280b552118d;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz02?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'icon': 'https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon',
'id': '840dr5re-aa24fe86f42b4815bf757280b552118d',
'openingHours': {'isOpen': False,
'label': 'Opening hours',
'structured': [{'duration': 'PT08H30M',
'recurrence': 'FREQ:DAILY;BYDAY:MO,TU,WE,TH,FR',
'start': 'T083000'}],
'text': 'Mon-Fri: 08:30 - 17:00'},
'position': [40.708655, -74.01111],
'title': 'HSBC',
'type': 'urn:nlp-types:place',
'vicinity': '117 Broadway<br/>New York, NY 10006'},
{'alternativeNames': [{'language': 'en',
'name': 'Federal Reserve Bank'}],
'averageRating': 0.0,
'category': {'href': 'https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'id': 'atm-bank-exchange',
'system': 'places',
'title': 'ATM/Bank/Exchange',
'type': 'urn:nlp-types:category'},
'distance': 609,
'having': [],
'href': 'https://places.sit.ls.hereapi.com/places/v1/places/840dr5re-ae53f05b1f9e4cb181fc29c2fd8efd40;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz03?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'icon': 'https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon',
'id': '840dr5re-ae53f05b1f9e4cb181fc29c2fd8efd40',
'position': [40.708861, -74.009352],
'title': 'Federal Reserve Bank of New York',
'type': 'urn:nlp-types:place',
'vicinity': '33 Liberty Pl<br/>New York, NY 10038'},
{'averageRating': 0.0,
'category': {'href': 'https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'id': 'atm-bank-exchange',
'system': 'places',
'title': 'ATM/Bank/Exchange',
'type': 'urn:nlp-types:category'},
'distance': 660,
'having': [],
'href': 'https://places.sit.ls.hereapi.com/places/v1/places/840dr5re-2719b12b4b244b8b808dd34014a66e63;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz04?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'icon': 'https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon',
'id': '840dr5re-2719b12b4b244b8b808dd34014a66e63',
'position': [40.70944, -74.01012],
'title': 'Berkshire Bancorp',
'type': 'urn:nlp-types:place',
'vicinity': '160 Broadway<br/>New York, NY 10038'},
{'averageRating': 0.0,
'category': {'href': 'https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'id': 'atm-bank-exchange',
'system': 'places',
'title': 'ATM/Bank/Exchange',
'type': 'urn:nlp-types:category'},
'distance': 1191,
'having': [],
'href': 'https://places.sit.ls.hereapi.com/places/v1/places/840dr5re-00e631bb6a614c74a85060fc21ddb9d7;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz05?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'icon': 'https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon',
'id': '840dr5re-00e631bb6a614c74a85060fc21ddb9d7',
'openingHours': {'isOpen': True,
'label': 'Opening hours',
'structured': [{'duration': 'PT24H00M',
'recurrence': 'FREQ:DAILY;BYDAY:TU,WE,TH,FR,SA,SU',
'start': 'T000000'}],
'text': 'Tue-Sun: 00:00 - 00:00'},
'position': [40.71392, -74.01469],
'title': 'American Express Company',
'type': 'urn:nlp-types:place',
'vicinity': '200 Vesey St<br/>New York, NY 10281'},
{'averageRating': 0.0,
'category': {'href': 'https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'id': 'atm-bank-exchange',
'system': 'places',
'title': 'ATM/Bank/Exchange',
'type': 'urn:nlp-types:category'},
'chainIds': ['1290'],
'distance': 1204,
'having': [],
'href': 'https://places.sit.ls.hereapi.com/places/v1/places/840dr5re-2692d9fbb3384f33af3d5eddce3fcf73;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz0xMA?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'icon': 'https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon',
'id': '840dr5re-2692d9fbb3384f33af3d5eddce3fcf73',
'openingHours': {'isOpen': False,
'label': 'Opening hours',
'structured': [{'duration': 'PT09H30M',
'recurrence': 'FREQ:DAILY;BYDAY:MO,TU,WE,TH,FR',
'start': 'T083000'}],
'text': 'Mon-Fri: 08:30 - 18:00'},
'position': [40.71386, -74.00676],
'title': 'Bank of America',
'type': 'urn:nlp-types:place',
'vicinity': '261 Broadway<br/>New York, NY 10007'},
{'averageRating': 0.0,
'category': {'href': 'https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'id': 'atm-bank-exchange',
'system': 'places',
'title': 'ATM/Bank/Exchange',
'type': 'urn:nlp-types:category'},
'distance': 1453,
'having': [],
'href': 'https://places.sit.ls.hereapi.com/places/v1/places/8403fv6k-0cf06c8d42f40193e3a9b8084fe4e33d;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz0xMQ?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'icon': 'https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon',
'id': '8403fv6k-0cf06c8d42f40193e3a9b8084fe4e33d',
'position': [40.71551, -74.00421],
'title': 'Justice Federal Credit Union',
'type': 'urn:nlp-types:place',
'vicinity': '26 Federal Plz<br/>New York, NY 10278'},
{'averageRating': 0.0,
'category': {'href': 'https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'id': 'atm-bank-exchange',
'system': 'places',
'title': 'ATM/Bank/Exchange',
'type': 'urn:nlp-types:category'},
'distance': 50,
'having': [],
'href': 'https://places.sit.ls.hereapi.com/places/v1/places/8403fv6k-621152dd2a180b3f25443a0eb5ce68e2;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz0xNg?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'icon': 'https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon',
'id': '8403fv6k-621152dd2a180b3f25443a0eb5ce68e2',
'openingHours': {'isOpen': True,
'label': 'Opening hours',
'structured': [{'duration': 'PT12H00M',
'recurrence': 'FREQ:DAILY;BYDAY:MO,TU,WE,TH,FR,SA',
'start': 'T090000'}],
'text': 'Mon-Sat: 09:00 - 21:00'},
'position': [40.70395, -74.01143],
'title': 'New York Cash Net',
'type': 'urn:nlp-types:place',
'vicinity': '85 Broad St<br/>New York, NY 10004'},
{'averageRating': 0.0,
'category': {'href': 'https://places.sit.ls.hereapi.com/places/v1/categories/places/hospital-health-care-facility?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'id': 'hospital-health-care-facility',
'system': 'places',
'title': 'Hospital or Healthcare Facility',
'type': 'urn:nlp-types:category'},
'distance': 50,
'having': [],
'href': 'https://places.sit.ls.hereapi.com/places/v1/places/8408lxx5-925d315190cb060336acf064d68ea7a7;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz0xNw?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'icon': 'https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/26.icon',
'id': '8408lxx5-925d315190cb060336acf064d68ea7a7',
'openingHours': {'isOpen': False,
'label': 'Opening hours',
'structured': [{'duration': 'PT08H00M',
'recurrence': 'FREQ:DAILY;BYDAY:MO,TU,WE,TH,FR',
'start': 'T090000'}],
'text': 'Mon-Fri: 09:00 - 17:00'},
'position': [40.70395, -74.01143],
'title': 'Life Mod',
'type': 'urn:nlp-types:place',
'vicinity': '85 Broad St<br/>New York, NY 10004'},
{'averageRating': 0.0,
'category': {'href': 'https://places.sit.ls.hereapi.com/places/v1/categories/places/hospital-health-care-facility?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'id': 'hospital-health-care-facility',
'system': 'places',
'title': 'Hospital or Healthcare Facility',
'type': 'urn:nlp-types:category'},
'distance': 50,
'having': [],
'href': 'https://places.sit.ls.hereapi.com/places/v1/places/840dr5re-72136d2caf4d41aca1a2daa21789e10b;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz0xOA?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'icon': 'https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/26.icon',
'id': '840dr5re-72136d2caf4d41aca1a2daa21789e10b',
'openingHours': {'isOpen': False,
'label': 'Opening hours',
'structured': [{'duration': 'PT06H30M',
'recurrence': 'FREQ:DAILY;BYDAY:MO,TU,WE,TH,FR',
'start': 'T070000'}],
'text': 'Mon-Fri: 07:00 - 13:30'},
'position': [40.70395, -74.01143],
'title': 'Symbio Physiotherapy',
'type': 'urn:nlp-types:place',
'vicinity': '85 Broad St<br/>New York, NY 10004'},
{'averageRating': 0.0,
'category': {'href': 'https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'id': 'atm-bank-exchange',
'system': 'places',
'title': 'ATM/Bank/Exchange',
'type': 'urn:nlp-types:category'},
'distance': 50,
'having': [],
'href': 'https://places.sit.ls.hereapi.com/places/v1/places/8408lxx5-158041e5aa340aea0d37533b0914dd91;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz0xOQ?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'icon': 'https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon',
'id': '8408lxx5-158041e5aa340aea0d37533b0914dd91',
'openingHours': {'isOpen': False,
'label': 'Opening hours',
'structured': [{'duration': 'PT12H00M',
'recurrence': 'FREQ:DAILY;BYDAY:MO,TU,WE,TH,FR,SA',
'start': 'T080000'}],
'text': 'Mon-Sat: 08:00 - 20:00'},
'position': [40.70395, -74.01143],
'title': 'Fast Payday Loan',
'type': 'urn:nlp-types:place',
'vicinity': '85 Broad St<br/>New York, NY 10004'}],
'next': 'https://places.sit.ls.hereapi.com/places/v1/discover/explore;context=Y2F0PWF0bS1iYW5rLWV4Y2hhbmdlJTJDaG9zcGl0YWwtaGVhbHRoLWNhcmUtZmFjaWxpdHkmZmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmb2Zmc2V0PTIwJnNpemU9MjA?in=40.703553%2C-74.011152%3Br%3D2000.0&app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg'},
'search': {'context': {'href': 'https://places.sit.ls.hereapi.com/places/v1/places/loc-dmVyc2lvbj0xO3RpdGxlPTYwK1BlYXJsK1N0O2xhdD00MC43MDM1NTM7bG9uPS03NC4wMTExNTI7c3RyZWV0PVBlYXJsK1N0O2hvdXNlPTYwO2NpdHk9TmV3K1lvcms7cG9zdGFsQ29kZT0xMDAwNDtjb3VudHJ5PVVTQTtkaXN0cmljdD1GaW5hbmNpYWwrRGlzdHJpY3Q7c3RhdGVDb2RlPU5ZO2NvdW50eT1OZXcrWW9yaztjYXRlZ29yeUlkPWJ1aWxkaW5nO3NvdXJjZVN5c3RlbT1pbnRlcm5hbA;context=c2VhcmNoQ29udGV4dD0x?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg',
'location': {'address': {'city': 'New York',
'country': 'United States',
'countryCode': 'USA',
'county': 'New York',
'district': 'Financial '
'District',
'house': '60',
'postalCode': '10004',
'stateCode': 'NY',
'street': 'Pearl St',
'text': '60 Pearl St<br/>New '
'York, NY '
'10004<br/>USA'},
'position': [40.703553, -74.011152]},
'type': 'urn:nlp-types:place'}}} ```
使用pandas.json_normalize
data
等于您的样本。
import pandas as pd
df = pd.json_normalize(data['results']['items'])
# extract lat & long from position
df[['lat', 'long']] = pd.DataFrame(df.position.tolist(), index=df.index)
# drop position column
df.drop(columns='position', inplace=True)
# move position x & y to index 3 & 4
col = df.pop('lat')
df.insert(3, col.name, col)
col = df.pop('long')
df.insert(4, col.name, col)
# remove chainIds from list
df = df.explode('chainIds')
print(df.head(3))
averageRating chainIds distance lat long having href icon id title type vicinity category.href category.id category.system category.title category.type openingHours.isOpen openingHours.label openingHours.structured openingHours.text alternativeNames
0.0 6113 727 40.71001 -74.00979 [] https://places.sit.ls.hereapi.com/places/v1/places/840dr5re-9b94731a418e41848c81389e9bbb5258;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz0w?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon 840dr5re-9b94731a418e41848c81389e9bbb5258 Capital One urn:nlp-types:place 176 Broadway<br/>New York, NY 10038 https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg atm-bank-exchange places ATM/Bank/Exchange urn:nlp-types:category False Opening hours [{'duration': 'PT09H00M', 'recurrence': 'FREQ:DAILY;BYDAY:MO,TU,WE,TH,FR', 'start': 'T090000'}] Mon-Fri: 09:00 - 18:00 NaN
0.0 2667 58 40.70382 -74.01174 [] https://places.sit.ls.hereapi.com/places/v1/places/840dr5re-ce5c5899421348eab75d05794548b34f;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz0x?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon 840dr5re-ce5c5899421348eab75d05794548b34f TD Bank urn:nlp-types:place 90 Broad St<br/>New York, NY 10004 https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg atm-bank-exchange places ATM/Bank/Exchange urn:nlp-types:category NaN NaN NaN NaN NaN
0.0 NaN 321 40.70526 -74.01422 [] https://places.sit.ls.hereapi.com/places/v1/places/840dr5re-efead63cf9b940a7a228c6e8bce1bfab;context=Zmxvdy1pZD0wMTA4YmNmMy01M2MxLTUyZmItOWMyYS1hZTg0ZDFjMWFhOWJfMTU4NzA4Mzg0MTUzMV8wXzg0NjYmcmFuaz0y?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg https://download.vcdn.cit.data.here.com/p/d/places2_stg/icons/categories/15.icon 840dr5re-efead63cf9b940a7a228c6e8bce1bfab Berkshire Bank urn:nlp-types:place 5 Broadway<br/>New York, NY 10004 https://places.sit.ls.hereapi.com/places/v1/categories/places/atm-bank-exchange?app_id=NRCOCm4yupXp5UUkFhyU&app_code=OqBcuShIgWoRS_NjlxDwfg atm-bank-exchange places ATM/Bank/Exchange urn:nlp-types:category NaN NaN NaN NaN NaN
只需 distance
和 for-loop
distance
在list
里面,所以你需要遍历每个列表来获取值。
for dist in data['results']['items']:
print(dist.get('distance'))
727
58
321
457
522
1341
567
609
660
1191
1204
1453
50
50
50
50