【发布时间】:2021-07-07 16:12:55
【问题描述】:
我正在尝试使用 Python 将 CSV 转换为多个 JSON,CSV 的每一行一个 JSON。
我希望 JSON 文件名是第一列中的数据,而 JSON 内容是其余列。
所以我的 CSV 看起来像这样:
Filename, CustomerName, CustomerCode
Customer1.json,Customer1,C001
Customer2.json,Customer2,C002
我正在尝试获取两个 JSON,一个名为 Customer1.json,其内容为 Customer1, C001(JSON 格式)。
我现在离它很远,但我有这个:
import pandas as pd
import json
df = csvfile.csv
for i in df.index:
result = df.to_json(orient="split")
parsed = json.loads(result)
json.dumps(parsed, indent=4)
df.filename.to_json("row{}.json".format(i))
非常感谢任何帮助!
【问题讨论】:
-
您能否包含一个示例输出文件内容?输出是 JSON 列表吗?