在熊猫中读取请求的JSON文件

时间:2020-02-05 13:55:45

标签: json pandas request

我正在学习如何在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进行排序,以便进一步处理它?

1 个答案:

答案 0 :(得分:0)

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

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
... ...                       ...               ...                 ...
相关问题