繁体   English   中英

如何将目录的所有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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM