const output = [
{user: 'john-smith',
totalMoney: 10},
{user: 'jane-doe',
totalMoney: 16}]
以下是完整的追溯:
import json
import pandas as pd
import collections
import os
path = '/home/vinay/hdfs/kafka-logs/event_tablenames.txt'
file_read = '/home/vinay/hdfs/kafka-logs/hdfs_events/'
table_file = '/home/hdfs/vinay/kafka-logs/events_tables/'
con_json = '/home/vinay/hdfs/kafka-logs/json_to_txt/'
os.chdir(file_read)
files=os.listdir('.')
for file in files:
line = file.split('.')[0]
with open(file ,'r') as f:
print (json.load(f))
data = json.load(f)
key = data[line]
od = collections.OrderedDict(sorted(key.items()))
df = pd.DataFrame(list(od.items()), columns=['col_name', 'type'])
df['col_name'].to_csv(con_json + line + '.txt',sep='\t', index=False, header=False)
答案 0 :(得分:1)
您没有显示问题中的错误的完整回溯,所以这只是一个猜测。
我认为问题是因为您试图对同一文件执行两次json.load(f)
。第一个使用整个文件,因此第二个失败。打开文件后,尝试更改前几行:
with open(file ,'r') as f:
data = json.load(f)
print(data)
答案 1 :(得分:0)