【发布时间】:2019-02-11 04:09:28
【问题描述】:
我正在尝试读取 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()?
标签: python json python-3.x pandas dataframe