【问题标题】:How do you read a geojason url into a geopandas dataframe or pandas dataframe?如何将 geojson url 读入 geopandas 数据框或 pandas 数据框?
【发布时间】:2017-04-24 08:37:09
【问题描述】:

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

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.7328970_000"mounttolls :"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_amoun t":"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": “特征”、“几何”:

【问题讨论】:

    标签: pandas anaconda geopandas


    【解决方案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'])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-05
      • 2021-02-11
      • 2020-08-13
      • 2020-12-12
      • 2021-11-22
      • 1970-01-01
      • 1970-01-01
      • 2022-06-13
      相关资源
      最近更新 更多