简体   繁体   中英

how to convert all json files of directory to text files in python?

I want to convert all json files of directory to text files through this command: but I got error. How can I change it?

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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