Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.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 未正确调用数据帧构造函数!使用JSON_Python_Json_Python 3.x_Pandas_Dataframe - Fatal编程技术网

Python 未正确调用数据帧构造函数!使用JSON

Python 未正确调用数据帧构造函数!使用JSON,python,json,python-3.x,pandas,dataframe,Python,Json,Python 3.x,Pandas,Dataframe,我试图读入一个json文件并转换为一个数据帧。但我无法使用两种不同的方法来完成 import os import pandas as pd for m_file in os.listdir('.'): if m_file.startswith('180830') and m_file.endswith('_out.json'): input_file2 = open(m_file, 'r') output_json = input_file2.read

我试图读入一个json文件并转换为一个数据帧。但我无法使用两种不同的方法来完成

import os
import pandas as pd


for m_file in os.listdir('.'):
    if m_file.startswith('180830') and m_file.endswith('_out.json'):
        input_file2 = open(m_file, 'r')
        output_json = input_file2.read()

        #output_df = pd.read_json(output_json, orient=str) #gives me ValueError: Expected object or value error
        output_df = pd.DataFrame(eval(output_json)) #gives me the contructor error
        print(output_df)

熊猫可以读取文件路径

尝试:


你的缩进看起来不适合初学者。修复了它,但这不是原因。你到底为什么要使用
eval()
而不是
json.load()
import os
import pandas as pd


for m_file in os.listdir('.'):
    if m_file.startswith('180830') and m_file.endswith('_out.json'):
        output_df = pd.DataFrame(m_file) 
        print(output_df)