【发布时间】:2021-06-16 07:40:25
【问题描述】:
我在处理 json 文件方面相对较新。我有一个 json 数据集,我想将其转换为带有相关标题的 CSV-
Headers = ['Transcripts', 'Food', 'Area', 'PriceRange']
数据格式如下:
[
{
"dial": [
{
"turn": 0,
"usr": {
"transcript": "I need to find an expensive restauant that's in the south section of the city.",
"slu": [
{
"act": "inform",
"slots": [
[
"pricerange",
"expensive"
]
]
},
{
"act": "inform",
"slots": [
[
"area",
"south"
]
]
}
]
},
"sys": {
"sent": "There are several restaurants in the south part of town that serve expensive food. Do you have a cuisine preference?",
"DA": [
"food"
]
}
},
{
"turn": 1,
"usr": {
"transcript": "No I don't care about the type of cuisine.",
"slu": [
{
"act": "inform",
"slots": [
[
"pricerange",
"expensive"
]
]
},
{
"act": "inform",
"slots": [
[
"food",
"dontcare"
]
]
},
{
"act": "inform",
"slots": [
[
"area",
"south"
]
]
}
]
},
"sys": {
"sent": "Chiquito Restaurant Bar is a Mexican restaurant located in the south part of town.",
"DA": []
}
},
{
"turn": 2,
"usr": {
"transcript": "What is their address?",
"slu": [
{
"act": "request",
"slots": [
[
"slot",
"address"
]
]
},
{
"act": "inform",
"slots": [
[
"pricerange",
"expensive"
]
]
},
{
"act": "inform",
"slots": [
[
"area",
"south"
]
]
},
{
"act": "inform",
"slots": [
[
"food",
"dontcare"
]
]
}
]
},
"sys": {
"sent": "There address is 2G Cambridge Leisure Park Cherry Hinton Road Cherry Hinton, it there anything else I can help you with?",
"DA": [
]
}
},
我的目标是像这样隔离它,如果 act = 'inform' 然后获取成绩单、区域、食物、价格范围。
我尝试将其转换为 CSV,但它存储了价格范围和昂贵等字符串。我希望价格范围作为我的数据的标题和昂贵,这是转换后的 csv 示例 -
【问题讨论】:
-
到目前为止你尝试过什么?向我们展示您的代码!
-
我使用了这个网络工具 - convertcsv.com/json-to-csv.htm
-
请edit您的问题包含您尝试过的任何代码,并显示您对该 JSON 的预期输出
-
您发布的JSON无效,最后缺少
]}]。