我从推特上获取了数据。目前,数据位于多个文件中,我无法将其合并到单个文件中
注意:所有文件均为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
我认为问题在于您的文件不是真正的json(或者更好,它们的结构是jsonl)。您有两种处理方法:
尝试下面这个问题,并让我知道它是否解决了您的问题:Loading JSONL file as JSON objects
您也可以尝试通过以下方式编辑代码:
每一行都是不同的json元素
相关问题 更多 >
编程相关推荐