如何将目录的所有 json 个文件转换为 python 中的文本文件?
how to convert all json files of directory to text files in python?
我想通过此命令将目录中的所有 json 个文件转换为文本文件:但出现错误。我该如何更改它?
import pandas as pd
df = pd.read_json(r"/media/New Volume/a3d/pdb/json_parser/ *.json ")
df.to_csv(r"/media/New Volume/a3d/pdb/json_parser/ *.txt ", index = False)
import os
import pandas as pd
# Get the list of json files, which are in the folder:
str_address = r"/media/New Volume/a3d/pdb/json_parser/"
lst_files = [i for i in os.listdir(str_address) if i.endswith(".json")]
# Loop through the json files
for file_ in lst_files:
df = pd.read_json(str_address + file_)
df.to_csv(str_address+ file_+ ".txt", index = False)
我想通过此命令将目录中的所有 json 个文件转换为文本文件:但出现错误。我该如何更改它?
import pandas as pd
df = pd.read_json(r"/media/New Volume/a3d/pdb/json_parser/ *.json ")
df.to_csv(r"/media/New Volume/a3d/pdb/json_parser/ *.txt ", index = False)
import os
import pandas as pd
# Get the list of json files, which are in the folder:
str_address = r"/media/New Volume/a3d/pdb/json_parser/"
lst_files = [i for i in os.listdir(str_address) if i.endswith(".json")]
# Loop through the json files
for file_ in lst_files:
df = pd.read_json(str_address + file_)
df.to_csv(str_address+ file_+ ".txt", index = False)