擅长:python、mysql、java
<p>您可以更改代码以将文件合并到有效的json对象中:</p>
<pre><code>combined_results = []
with open('combined_results.json', 'w', encoding='utf-8') as outfile:
for file in files:
f = open(file, 'r')
combined_results.append(json.load(f)[0])
json.dump(combined_results, outfile)
</code></pre>
<p>现在要在数据帧中读取此文件,请尝试<code>pd.read_json</code>:</p>
^{pr2}$
<p><strong>更新:</strong></p>
<p>实际上根本不需要<code>combined_results.json</code>文件。除非您希望将文件合并到以后要使用的单个文件中,否则可以直接将<code>combined_results</code>的列表转换为数据帧。在</p>
<pre><code>combined_results = []
for file in files:
f = open(file, 'r')
combined_results.append(json.load(f)[0])
pd.DataFrame(combined_results)
</code></pre>