我有一个CSV文件,其中包含以下数据:enter image description here我正在使用pandas和python。
我希望JSON数据如下:
{
"VMName": "vm101",
"tags": [
{"scope": "Environment", "tag": "Production"},
{"scope": "Application", "tag": "App1"},
{"scope": "Tier", "tag": "Web"}
]
"VMName": "vm102",
"tags": [
{"scope": "Environment", "tag": "Production"},
{"scope": "Application", "tag": "App1"},
{"scope": "Tier", "tag": "App"}
]
"VMName": "vm103",
"tags": [
{"scope": "Environment", "tag": "Production"},
{"scope": "Application", "tag": "App1"},
{"scope": "Tier", "tag": "DB"}
]
"VMName": "vm104",
"tags": [
{"scope": "Environment", "tag": "UAT"},
{"scope": "Application", "tag": "App1"},
{"scope": "Tier", "tag": "Web"}
]
"VMName": "vm105",
"tags": [
{"scope": "Environment", "tag": "UAT"},
{"scope": "Application", "tag": "App1"}
]
"VMName": "vm106",
"tags": [
{"scope": "Environment", "tag": "UAT"},
{"scope": "Application", "tag": "App1"},
{"scope": "Tier", "tag": "DB"}
]
}
字符串
如何使用Pandas实现这一点
1条答案
按热度按时间xiozqbni1#
首先,您的期望的JSON无效,如果您需要CSV中的有效JSON,您可以这样做,而无需使用
pandas
字符串
data.csv
型
data.json
型