【发布时间】:2021-02-02 11:43:56
【问题描述】:
我已从 Twitter 中提取数据。目前,数据在多个文件中,我无法将其合并到一个文件中。
注意:所有文件均为 JSON 格式。
It has been suggested 与 glop to compile JSON files 合作
我编写了这段代码,正如我在一些关于使用 Python 合并 JSON 的教程中看到的那样
from glob import glob
import json
import pandas as pd
with open('Desktop/json/finalmerge.json', 'w') as f:
for fname in glob('Desktop/json/*.json'): # Reads all json from the current directory
with open(fname) as j:
f.write(str(j.read()))
f.write('\n')
我成功合并了所有文件,现在文件是 finalmerge.json。
现在我按照几个线程中的建议使用了这个:
df_lines = pd.read_json('finalmerge.json', lines=True)
df_lines
1000000*23 columns
Then, what I should do to make each feature in separate columns?
I'm not sure why what's wrong with JSON files, I checked the file that I merge and I found it's not valid as JSON file? what I should do to make this as a data frame?
The reason I am asking this is that I have very basic python knowledge and all the answers to similar questions that I have found are way more complicated than I can understand. Please help this new python user to convert multiple Json fils to one JSON file.
Thank you
【问题讨论】: