簡體   English   中英

遍歷CSV的每一行,並使用Python-Pandas寫入文件夾中的單個JSON文件

[英]Iterate through each row of CSV and write into individual JSON files in a folder using Python-Pandas

我正在嘗試使用輸入作為CSV為每一行生成單獨的JSON文件並將其保存到輸出文件夾中。 使用循環邏輯。

假設data是您的問題中定義的字典,那么以下代碼可以滿足您的需求:

data_path = 'C:/Users/usasxs174/Desktop/ETL/Data_tables/MT/'
for i, data_item in enumerate(data['entities']):
    with open(data_path + str(i) + '.json', 'w') as outfile:
        outfile.write(json.dumps(data_item, indent=4))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM