使用python将嵌套字典的特定字段导入csv

问题描述 投票:0回答:0

我有嵌套的字典,我想从中创建一个 CSV 文件。 CSV 中的表格只需要包含特定字段。我的字典看起来像这样:

rows = { 'signature1': { 'element': 'element1', 'process': 'process1', 'process_stack' : 'foo()\n callfoo()\nhelper_function()\ninitialize()\n', 'file_name' : 'file_1.txt'},
         'signature2': { 'element': 'element2', 'process': 'process2', 'process_stack' : 'foo2()\n callfoo2()\nhelper_function()\ninitialize()\n', 'file_name' : 'file_2.txt'},
         'signature3': {'element': 'element3', 'process': 'process3','process_stack': 'foo3()\n callfoo3()\nhelper_function()\ninitialize()\n','file_name': 'file_3.txt'}}```

我需要我的 CSV 将字段设置为

process signature filename
process1 signature1 file_1.txt
process2 signature2 file_2.txt
process3 signature3 file_3.txt
python python-3.x export-to-csv
© www.soinside.com 2019 - 2024. All rights reserved.