首页 > 解决方案 > 在 pandas 中读取请求的 JSON 文件

问题描述

我正在学习如何在 Pandas 中使用 JSON 文件。

可以通过以下代码行读取包含数据的公开可用 JSON 文件:

import requests 
import json
url = 'https://data.seattle.gov/resource/65db-xm6k.json'
response = requests.get(url) 
data_json = response.json()

如何对列上的 data_json 进行排序,以便进一步处理它?

标签: jsonpandasrequest

解决方案


就像读取 json 文件一样简单pandas

import pandas as pd
df = pd.DataFrame(data_json)
df

    date                      fremont_bridge    fremont_bridge_sb   fremont_bridge_nb
0   2012-10-03T00:00:00.000   13                4                   9
1   2012-10-03T01:00:00.000   10                4                   6
2   2012-10-03T02:00:00.000   2                 1                   1
3   2012-10-03T03:00:00.000   5                 2                   3
4   2012-10-03T04:00:00.000   7                 6                   1
... ...                       ...               ...                 ...

推荐阅读