如何将 geojson url 读入 geopandas 数据框或 pandas 数据框?

How do you read a geojason url into a geopandas dataframe or pandas dataframe?

我试过这个但是我的前景很乱

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.279999999999999","dropoff_longitude":"-73.870570000000001","pickup_latitude":"40.732897000000001","tolls_amount":"0","tip_amount":"0","payment_type":"CRD","fare_amount":"37","pickup_longitude":"-73.991167000000004","passenger_count":"6","store_and_fwd_flag":null, "extra":"0","vendorid":"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","coordinates":[-74.00296,40.722112]},"properties":{"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":

你可以试试pandas.io.json.json_normalize。在这种情况下,它无法处理完整的 json return,但如果您在 json 中指定 'features' 键,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'])