英文:
merging multiple jsons into one with data export
问题
我有一个包含多个JSON文件的文件夹,其中包含如下数据:
file1
myname,
myname2,
myname3,
myname,
myname,
myname3,
file 2
myname5,
myname,
myname2,
myname5,
myname3,
myname3,
我想要一个文件,给我类似以下的内容:
myname, 4,
myname2, 2,
myname3, 4,
myname5, 2,
简而言之,它应该统计文本的所有出现并导出它们重复了多少次。
我想知道如何实现这个目标,需要使用什么编程语言?是否可以在云端完成这个任务?
英文:
I have a folder containing multiple json files with a data like:
file1
myname,
myname2,
myname3,
myname,
myname,
myname3,
file 2
myname5,
myname,
myname2,
myname5,
myname3,
myname3,
I want a file that give my something like this:
myname, 4,
myname2, 2,
myname3, 4,
myname5, 2,
in a nutshell, it should could all occurrences of a text and export how many numbers it repeated.
I want to know how can I achieve this, what language? is it possible to do it in cloud?
答案1
得分: 1
以下是翻译好的部分:
"its not very clear what you want. if you put more details on your question maybe we can work on a better answer. If possible provide a complete example of the json file."
- "这不太清楚你想要什么。如果你在问题中提供更多细节,也许我们可以提供更好的答案。如果可能的话,请提供一个完整的JSON文件示例。"
"But if I understood correctly what you need. I think it can easily be done in python."
- "但如果我理解你的需求正确,我认为可以很容易在Python中完成。"
"Example of code:"
- "示例代码:"
"Now you have a json file were they keys are the names and the corresponding values is the number of times they are repeated."
- "现在你有一个JSON文件,其中键是名称,相应的值是它们重复的次数。"
英文:
its not very clear what you want. if you put more details on your question maybe we can work on a better answer. If possible provide a complete example of the json file.
But if I understood correctly what you need. I think it can easily be done in python.
Example of code:
import pandas as pd
FileWithAllData = {}
myname_df = pd.read_json(".../file1.json")
myname_df = myname_df.groupby(['columns_with_the_names', as_index=False).agg('count')[['columns_with_the_names','columns_with_quantity"]]
myname_df = myname_df.to_dict(orient='records')
#Saving as json file
import json
js = json.dumps(myname_df)
# Open new json file if not exist it will create
fp = open('myname_df.json', 'myname_df')
# write to json file
fp.write(js)
# close the connection
fp.close()
Now you have a json file were they keys are the names and the corresponding values is the number of times they are repeated.
I hope it helps you.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论