如何修改此python脚本以获得相同的json文件而不使用HightSection?

如何修改此python脚本以获得相同的json文件而不使用HightSection?,python,arrays,json,Python,Arrays,Json,目前,我正在尝试从csv文件导入由以下python脚本创建的json文件 import csv, json csvFilePath ='USvideos.csv' jsonFilePath = 'USvideos.json' data = {} with open(csvFilePath, encoding = 'utf8') as csvFile: csvReader = csv.DictReader(csvFile) for csvRow in csvReader:

目前,我正在尝试从csv文件导入由以下python脚本创建的json文件

import csv, json

csvFilePath ='USvideos.csv'
jsonFilePath = 'USvideos.json'
data = {}

with open(csvFilePath, encoding = 'utf8') as csvFile:
    csvReader = csv.DictReader(csvFile)
    for csvRow in csvReader:
        video_id = csvRow['video_id']
        data[video_id] = csvRow

with open(jsonFilePath, 'w') as jsonFile:
    jsonFile.write(json.dumps(data, indent=4))
问题陈述问题在于,我需要通过修改python脚本来获得一个不带括号部分的json文件

(“2kyS6SvSYSE”:{
“视频id”:“2kyS6SvSYSE”,
“趋势日期”:“17.20.11”,
“标题”:“我们想谈谈我们的婚姻”
},
(“1ZAPwfrtAFY”:{
“视频id”:“1ZAPwfrtAFY”,
“趋势分析日期”:“17.20.11”
}
解决问题的目的
我需要解决这个问题,因为我想以MongoDB适当地导入数据,猜测您需要的输出JSON格式,但是您能试试吗

import csv, json

csvFilePath ='USvideos.csv'
jsonFilePath = 'USvideos.json'
data = []

with open(csvFilePath, encoding = 'utf8') as csvFile:
    csvReader = csv.DictReader(csvFile)
    for csvRow in csvReader:
        data.append(csvRow)

with open(jsonFilePath, 'w') as jsonFile:
    jsonFile.write(json.dumps(data, indent=4))

我建议您将
csvRow
s写入
pd.DataFrame
而不是字典。这将允许您使用
.to_json(orient='records')
轻松地将它们保存到.json而无需索引列,非常感谢!!!它起作用了。我对同一个JSON文件还有另一个问题。事实证明,我只需要使用{}而不是使用coma来分离每个对象。你能给我一个解决方案吗?不清楚你需要什么。请张贴你想要的样品。每个输入和所需输出只需几条记录。