Python 未正确调用数据帧构造函数!使用JSON
我试图读入一个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
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)