【发布时间】:2019-08-13 21:36:24
【问题描述】:
我正在尝试了解如何将未正确解析/提取的 JSON 数据转换为 (Pandas) DataFrame。
我正在使用 python (3.7.1) 并尝试了读取 JSON 数据的常用方法。实际上,如果我使用 transpose 或 axis=1 语法,代码就可以工作。但是使用它会完全忽略数据中的大量值或变量,我 100% 确信代码可能正在工作,但没有给出预期的结果。
import pandas as pd
import numpy as np
import csv
import json
sourcefile = open(r"C:\Users\jadil\Downloads\chicago-red-light-and-speed-camera-data\socrata_metadata_red-light-camera-violations.json")
json_data = json.load(sourcefile)
#print(json_data)
type(json_data)
dict
## this code works but is not loading/reading complete data
df = pd.DataFrame.from_dict(json_data, orient="index")
df.head(15)
#This is what I am getting for the first 15 rows
df.head(15)
0
createdAt 1407456580
description This dataset reflects the daily volume of viol...
rights [read]
flags [default, restorable, restorePossibleForType]
id spqx-js37
oid 24980316
owner {'type': 'interactive', 'profileImageUrlLarge'...
newBackend False
totalTimesRated 0
attributionLink http://www.cityofchicago.org
hideFromCatalog False
columns [{'description': 'Intersection of the location...
displayType table
indexUpdatedAt 1553164745
rowsUpdatedBy n9j5-zh
【问题讨论】:
标签: python json pandas dataframe jupyter-notebook