我试过这个,但我的前景很混乱
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","功能":[{" type":" Feature" ,"几何":{"类型":"点","坐标":[ - 73.87057,40.773757]},"属性":{" tpep_dropoff_datetime":" 2013-04- 02T16:00:00.000"," trip_distance":" 11.279999999999999&#34 ;," dropoff_longitude":" -73.870570000000001"," pickup_latitude":" 40.732897000000001"," tolls_amount": " 0"" tip_amount":" 0"" payment_type":" CRD"" fare_amount& #34;:" 37"" pickup_longitude":" -73.991167000000004"" passenger_count":" 6" " store_and_fwd_flag":空,"额外":" 0""厂商ID":" VTS"&# 34; pickup_location" {"类型":"点""坐标":[ - 73.991167,40.732897]}," TOTAL_AMOUNT&#34 ;:" 37.5"" tpep_pickup_datetime":" 2013-04-02T15:22:00.0 00"" dropoff_latitude":" 40.773757000000003"" ratecodeid":" 1"" mta_tax" :" 0.5"}},{"类型":"特征""几何" {"类型" :"点""坐标":[ - 74.00296,40.722112]},"属性" {" tpep_dropoff_datetime":" 2013-07-19T07:52:00.000"" trip_distance":" 5.5"" dropoff_longitude":" -74.002960000000002&# 34;," pickup_latitude":" 40.766105000000003"" tolls_amount":" 0"" tip_amount":& #34; 3.8999999999999999"" payment_type":" CRD"" fare_amount":" 19.5"" pickup_longitude":" -73.954407000000003"" passenger_count":" 1"" store_and_fwd_flag":空,"额外& #34;:" 0""厂商ID":" VTS"" pickup_location" {"类型&#34 ;: "点""坐标":[ - 73.954407,40.766105]}," TOTAL_AMOUNT":"&23.899999999999999 #34;" tpep_pickup_datetime":" 2013-07-19T07:33:00.000"" dropoff_latitude":" 40.722112000000003&#34 ;, " ratecodeid":" 1"" mta_tax":" 0.5"}},{"类型":& #34;特征""几何":
答案 0 :(得分:1)
您可以尝试pandas.io.json.json_normalize
。在这种情况下,它无法处理完整的json返回,但如果在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'])