如果Python中不存在For循环迭代,则获取空值

如果Python中不存在For循环迭代,则获取空值,python,json,pandas,csv,dataframe,Python,Json,Pandas,Csv,Dataframe,我有几个静态键列EmployeeId、type和几个来自first FOR循环的列 而在第二个FOR循环中,如果我有一个特定的键,那么只有值应该附加到现有的数据帧列,否则从第一个FOR循环获取的列应该保持不变 循环输出的第一个: "EmployeeId","type","KeyColumn","Start","End","Country","Target","CountryId","TargetId" "Emp1","Metal","1212121212","2000-06-17","9999-

我有几个静态键列EmployeeId、type和几个来自first FOR循环的列

而在第二个FOR循环中,如果我有一个特定的键,那么只有值应该附加到现有的数据帧列,否则从第一个FOR循环获取的列应该保持不变

循环输出的第一个:

"EmployeeId","type","KeyColumn","Start","End","Country","Target","CountryId","TargetId"
"Emp1","Metal","1212121212","2000-06-17","9999-12-31","","","",""
"EmployeeId","type","KeyColumn","Start","End","Country","Target","CountryId","TargetId"
"Emp1","Metal","1212121212","2000-06-17","9999-12-31","","AMAZON","1",""
"Emp1","Metal","1212121212","2000-06-17","9999-12-31","","FLIPKART","2",""
在第二个For循环之后,我有以下输出:

"EmployeeId","type","KeyColumn","Start","End","Country","Target","CountryId","TargetId"
"Emp1","Metal","1212121212","2000-06-17","9999-12-31","","","",""
"EmployeeId","type","KeyColumn","Start","End","Country","Target","CountryId","TargetId"
"Emp1","Metal","1212121212","2000-06-17","9999-12-31","","AMAZON","1",""
"Emp1","Metal","1212121212","2000-06-17","9999-12-31","","FLIPKART","2",""
根据代码,如果我有可用的Employee标记,我有以上2条记录,但我可能有几个没有Employee标记的json文件,那么输出应该和第一个循环输出保持相同

但根据我的代码,我得到了0条记录。如果我的编码方式不对,请帮助我

真的很抱歉——如果提问的方式不清楚,因为我是python新手。请在下面的超链接中查找代码

请查找以下代码

    for i in range(len(json_file['enty'])):
        temp = {}
        temp['EmployeeId'] = json_file['enty'][i]['id']
        temp['type'] = json_file['enty'][i]['type']
        for key in json_file['enty'][i]['data']['attributes'].keys(): 
            if(key == 'Employee'):
                for j in range(len(json_file['enty'][i]['data']['attributes']['Employee']['group'])):
                    for key in json_file['enty'][i]['data']['attributes']['Employee']['group'][j].keys():
                        try:
                            temp[key] = json_file['enty'][i]['data']['attributes']['Employee']['group'][j][key]['values'][0]['value']
                        except:
                            temp[key] = None

                    temp_df = pd.DataFrame([temp])
                    df = pd.concat([df, temp_df], sort=True)

如果Employee标记不可用,我将获得0条记录作为输出,但我希望1条记录作为第一个for循环


不要将代码发布为images@barbsan .. 我只是通过粘贴代码编辑了这个问题。。那好吗?请帮我做任何事情suggestion@barbsan .. 还添加了示例源Json文件。@有人能帮我解决这个问题吗?不要将代码发布为images@barbsan .. 我只是通过粘贴代码编辑了这个问题。。那好吗?请帮我做任何事情suggestion@barbsan .. 还添加了示例源Json文件。@请有人帮我解决这个问题。