请问复杂字典转CSV?

示例:
if name == 'main':
assignment_sample = { # assignment 顶层为python字典
'type': 'rectangle', # 标注对象工具类型, 题目中只有矩形框一种, 可忽略
'properties': [{ # 要求标注对象的属性. 数组, 其中每个字典描述一个属性, 数目不定
'id': 1, # 此属性项的唯一id
'name': '对象类型', # 此属性项的名称
'items': ['行人', '车'], # 属性值备选项. 对应annotations中的属性值为其中之一.
}],
}

annotations_sample = [{  # 标注结果, 数组, 其中每个元素描述一个标注对象. 图里画了多少框, 就有多少个
    'object_id': 1,  # 一张图中标注对象的唯一id
    'rectangle': {  # 题目只有矩形框
        'x1': 100,  # 框的坐标, 整数. (x1, y1)是框的左上角点, (x2, y2)是框的右下角点. (图片左上角坐标为(0, 0))
        'y1': 10,
        'x2': 201,
        'y2': 250,
    },
    'properties': [{  # 每项表示一个属性. 每个属性一定有值, 所以其长度等于assignment中properties的长度
        'property_id': 1,  # 对应assignment['properties']中的'id', 表示此项是哪个属性项.
        'value': '行人',  # 标注的属性值
    }]
}]

convert_to_csv(assignment_sample, annotations_sample)

转出格式:
object_id,对象类型,面积
1,行人,3000

把相同的key的值放到同一个list里面,然后csv.writer.writerow直接写进去就可以了

你也没说输出格式中的数据是怎么来的啊

字典转DataFrame,再转csv
【基础汇总】——python数据分析必备三大工具_貮叁的博客-CSDN博客