0

我试过这个,但我的前景很混乱

from io import StringIO, BytesIO
Trial ='https://data.cityofnewyork.us/resource/t7ny-aygi.geojson?vendorid=VTS&payment_type=CRD&$limit=500'
trialck = requests.get(Trial).content
final = pd.read_csv(StringIO(trialck.decode('utf-8')), sep = '\t')
final.head()

{ "type": "FeatureCollection", "features":[{"type":"Feature","geometry":{"type":"Point","coordinates": [-73.87057,40.773757]},"properties ":{"tpep_dropoff_datetime":"2013-04- 02T16:00:00.000","trip_distance":"11.27999999999999","dropoff_longitude":"-73.870570000000001","pickup_latitude":"40.73289700000000001","toll ","tip_amount":"0","payment_type":"CRD","fare_amount":"37","pickup_longitude":"-73.991167000000004","passenger_count":"6","store_and_fwd_flag":null,"额外":"0","供应商":"VTS","pickup_location":{"type":"Point","coordinates":[-73.991167,40.732897]},"total_amount":"37.5","tpep_pickup_datetime":"2013-04-02T15:22:00.000 ","dropoff_latitude":"40.773757000000003","ratecodeid":"1","mta_tax":"0.5"}},{"type":"Feature","geometry":{"type":"Point", "坐标":[-74.00296,40.722112]},"属性":{"tpep_dropoff_datetime":"2013-07-19T07:52:00.000","trip_distance":"5.5","dropoff_longitude":"-74.002960000000002", "pickup_latitude":"40.766105000000003","tolls_amount":"0","tip_amount":"3.8999999999999999","payment_type":"CRD","fare_amount":"19.5","pickup_longitude":"-73.954407000000003","passenger_count":"1","store_and_fwd_flag":null,"extra":"0","vendorid" :"VTS","pickup_location":{"type":"Point","coordinates":[-73.954407,40.766105]},"total_amount":"23.899999999999999","tpep_pickup_datetime":"2013-07-19T07:33 :00.000","dropoff_latitude":"40.722112000000003","ratecodeid":"1","mta_tax":"0.5"}},{"type":"Feature","geometry":954407000000003","passenger_count":"1","store_and_fwd_flag":null,"extra":"0","vendorid":"VTS","pickup_location":{"type":"Point","coordinates": [-73.954407,40.766105]},"total_amount":"23.899999999999999","tpep_pickup_datetime":"2013-07-19T07:33:00.000","dropoff_latitude":"40.722112000000003","ratecodeid":"1","mta_tax ":"0.5"}},{"type":"Feature","geometry":954407000000003","passenger_count":"1","store_and_fwd_flag":null,"extra":"0","vendorid":"VTS","pickup_location":{"type":"Point","coordinates": [-73.954407,40.766105]},"total_amount":"23.899999999999999","tpep_pickup_datetime":"2013-07-19T07:33:00.000","dropoff_latitude":"40.722112000000003","ratecodeid":"1","mta_tax ":"0.5"}},{"type":"Feature","geometry":766105]},"total_amount":"23.899999999999999","tpep_pickup_datetime":"2013-07-19T07:33:00.000","dropoff_latitude":"40.722112000000003","ratecodeid":"1","mta_tax":"0.5 "}},{"type":"Feature","geometry":766105]},"total_amount":"23.899999999999999","tpep_pickup_datetime":"2013-07-19T07:33:00.000","dropoff_latitude":"40.722112000000003","ratecodeid":"1","mta_tax":"0.5 "}},{"type":"Feature","geometry":

4

1 回答 1

3

你可以试试pandas.io.json.json_normalize。在这种情况下,它无法处理完整的 json 返回,但如果您'features'在 json 中指定键,pandas 可以将其转换为数据帧。

import requests
url = 'https://data.cityofnewyork.us/resource/t7ny-aygi.geojson?vendorid=VTS&payment_type=CRD&$limit=500'
response = requests.get(url)
data = response.json()
df = pd.io.json.json_normalize(data['features'])
于 2016-12-09T00:00:47.660 回答