Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python usnparser将类似json的数据转换为数据帧_Python_Json_Python 3.x_Pandas - Fatal编程技术网

Python usnparser将类似json的数据转换为数据帧

Python usnparser将类似json的数据转换为数据帧,python,json,python-3.x,pandas,Python,Json,Python 3.x,Pandas,我有如下输出的usnparser数据(仲裁字段): 我试着和熊猫一起读它,如下所示: data = pathtomyfile pd.read_json(data, orient='records') 我还尝试使用json,如下所示: data = pathtomyfile pd.read_json(data, orient='records') data=json.dumps(pathtomyfile) pd.read_json(数据,orient='records') 如何将数据传送到数据

我有如下输出的usnparser数据(仲裁字段):

我试着和熊猫一起读它,如下所示:

data = pathtomyfile
pd.read_json(data, orient='records')
我还尝试使用json,如下所示:

data = pathtomyfile
pd.read_json(data, orient='records')
data=json.dumps(pathtomyfile) pd.read_json(数据,orient='records')


如何将数据传送到数据帧

这是一种方法,但您需要编辑文件中的数据:

import pandas as pd
import ast

with open(pathtomyfile) as f:
    data = f.read()
    data = '[' + data.replace('\n', '').replace('}', '},') + ']' #convert it to list of dicts
    df = pd.DataFrame(ast.literal_eval(data))
    df
#thisisafield  thisisanewf    LastField
#THISISAVALUE  ThisIsANewVal  LastValue
#THISISAVALUE1 ThisIsANewVal1 LastValue1
要使数据
json
可转储,请执行以下操作:

data = '[' + data.replace('\n', '').replace('}', '},', data.count('}')-1) + ']'
df = pd.read_json(data)

我觉得这像是迪克特