Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何为每列创建具有不同行的多列_Python_Json_Pandas_Csv - Fatal编程技术网

Python 如何为每列创建具有不同行的多列

Python 如何为每列创建具有不同行的多列,python,json,pandas,csv,Python,Json,Pandas,Csv,我当前被阻止,因为我想创建一个CSV文件,第一列仅用键填充,第二列用值和标题填充。这样地: 但实际上是这样的: 我的JSON测试文件: { "name":"<customer>_<datetime>.zip", "status":"OK", "lib_status":"SUCCESS", "ID":" ", "ID_emitter":"<customer>", "recipient":" ", "validator":{ "send

我当前被阻止,因为我想创建一个
CSV
文件,第一列仅用键填充,第二列用值和标题填充。这样地:

但实际上是这样的:

我的JSON测试文件:

{
 "name":"<customer>_<datetime>.zip",
 "status":"OK",
 "lib_status":"SUCCESS",
 "ID":" ",
 "ID_emitter":"<customer>",
 "recipient":" ",
 "validator":{
     "sender_email_address":"example@example.com",
     "sender_email_address_no_reply":"example@example.com"
     },
 "connexFileList":[
   {
        "connexFile":"<customer>_<datetime>",
        "type":"json"
   }
   ],
  "PReS":{
    "domain":" ",
    "client":" ",
    "inputFlowList":[
        {
            "inputFile":" ",
            "type":" ",
            "status":" "
        }
        ]
    }
   }
但这不是我想要的
CSV
,而且
['',…]的原始数据也没有真正优化过。。。
我认为解决方案是
pd.MultiIndex
pd.Series
,但我不知道如何在我的代码中应用这两种解决方案。

试试这个:

raw_data = {
 "firstitem": [name, status, lib_status, ID_emitter, '', '', '', '', ''],
 " ": ['connexFile','type','', '', '', '', '', '', ''],
 "connexFileList": [connexFile, type2, '', '', '','', '', '', ''],
 "PReS": ['','','','','','', inputFile, type3, status2],
"": ['inputFile','type','status', '', '', '', '', '', '']
 }

df = pd.DataFrame(raw_data,
           index=pd.Index(['name', 'status', 'lib_status', 'ID_emitter', 
                           '','','', '', '']),
           columns=pd.Index(['firstitem', ' ','connexFileList','', 'PReS'])
           )

这正是我想要的!谢谢,但是你对优化原始数据有什么想法吗,主要是这些列表
['','','',…]
?@PunkyLama我很高兴它解决了你的问题。。如果需要,可以将解决方案标记为已接受。让我看看我是否可以帮助优化
raw_data = {
 "firstitem": [name, status, lib_status, ID_emitter, '', '', '', '', ''],
 " ": ['connexFile','type','', '', '', '', '', '', ''],
 "connexFileList": [connexFile, type2, '', '', '','', '', '', ''],
 "PReS": ['','','','','','', inputFile, type3, status2],
"": ['inputFile','type','status', '', '', '', '', '', '']
 }

df = pd.DataFrame(raw_data,
           index=pd.Index(['name', 'status', 'lib_status', 'ID_emitter', 
                           '','','', '', '']),
           columns=pd.Index(['firstitem', ' ','connexFileList','', 'PReS'])
           )