使用for循环解压缩列表列表的麻烦

时间:2019-11-19 10:58:26

标签: python pandas

我有几列,每列都有列表列表和嵌套列表中的值。

我一直试图将列表解压缩到单独的列中,但未成功。由于每列在另一个列表中都有3个列表,因此我尝试将这三个列表解压缩为要解压缩的每个列的三个单独的列。

我已经尝试过,创建一个列名列表来容纳未打包的列表,并创建一个我想解包的列名列表(scorecard_var)

from tqdm import tqdm
def judge_scores(col_name):
    return merged[col_name].apply(pd.Series)
#creating a list to house unpacked columns
col_names =list(chain.from_iterable(('first'+str(i),'second'+str(i),'third'+str(i)) for i in range(1,85))) 
#iterate through list of columns to unpack, unpack and house in col_names columns
for i in tqdm(scorecard_var):
    for x,y,z in zip(*[iter(col_names)]*3):
        merged[[x,y,z]] = judge_scores(i)

这会显示错误消息:

  

ValueError:列的长度必须与键的长度相同

据我所知,键列表应与列匹配

我在我的数据样本上附加了一个链接 data

它包含大量数据(每行超过1000列),所以我认为将链接附加到示例而不是将其添加到我的问题中更有意义

这是我的数据的另一个示例:

{'JudgeID1': {0: ['[]', '[]', '[]'], 3: []},
 'JudgeID2': {0: ['[]', '[]', '[]'], 3: ['[]', '[]', '[]']},
 'JudgeID3': {0: ['[]', '[]', '[]'], 3: []},
 'JudgeID4': {0: ['[]', '[]', '[]'], 3: []},
 'JudgeID5': {0: ['[40 36]', '[40 36]', '[39 37]'], 3: ['[]', '[]', '[]']},
 'JudgeID6': {0: nan, 3: nan},
 'JudgeID7': {0: nan, 3: nan},
 'JudgeID8': {0: nan, 3: nan},
 'JudgeID9': {0: nan, 3: nan},
 'JudgeID10': {0: nan, 3: nan},
 'JudgeID11': {0: nan, 3: nan},
 'JudgeID12': {0: nan, 3: nan},
 'JudgeID13': {0: nan, 3: nan},
 'JudgeID14': {0: nan, 3: nan},
 'JudgeID15': {0: nan, 3: nan},
 'JudgeID16': {0: nan, 3: nan},
 'JudgeID17': {0: nan, 3: nan},
 'JudgeID18': {0: nan, 3: nan},
 'JudgeID19': {0: nan, 3: nan},
 'JudgeID20': {0: nan, 3: nan},
 'JudgeID21': {0: nan, 3: nan},
 'JudgeID22': {0: nan, 3: nan},
 'JudgeID23': {0: nan, 3: nan},
 'JudgeID24': {0: nan, 3: nan},
 'JudgeID25': {0: nan, 3: nan},
 'JudgeID26': {0: nan, 3: nan},
 'JudgeID27': {0: nan, 3: nan},
 'JudgeID28': {0: nan, 3: nan},
 'JudgeID29': {0: nan, 3: nan},
 'JudgeID30': {0: nan, 3: nan},
 'JudgeID31': {0: nan, 3: nan},
 'JudgeID32': {0: nan, 3: nan},
 'JudgeID33': {0: nan, 3: nan},
 'JudgeID34': {0: nan, 3: nan},
 'JudgeID35': {0: nan, 3: nan},
 'JudgeID36': {0: nan, 3: nan},
 'JudgeID37': {0: nan, 3: nan},
 'JudgeID38': {0: nan, 3: nan},
 'JudgeID39': {0: nan, 3: nan},
 'JudgeID40': {0: nan, 3: nan},
 'JudgeID41': {0: nan, 3: nan},
 'JudgeID42': {0: nan, 3: nan},
 'JudgeID43': {0: nan, 3: nan},
 'JudgeID44': {0: nan, 3: nan},
 'JudgeID45': {0: nan, 3: nan},
 'JudgeID46': {0: nan, 3: nan},
 'JudgeID47': {0: nan, 3: nan},
 'JudgeID48': {0: nan, 3: nan},
 'JudgeID49': {0: nan, 3: nan},
 'JudgeID50': {0: nan, 3: nan},
 'JudgeID51': {0: nan, 3: nan},
 'JudgeID52': {0: nan, 3: nan},
 'JudgeID53': {0: nan, 3: nan},
 'JudgeID54': {0: nan, 3: nan},
 'JudgeID55': {0: nan, 3: nan},
 'JudgeID56': {0: nan, 3: nan},
 'JudgeID57': {0: nan, 3: nan},
 'JudgeID58': {0: nan, 3: nan},
 'JudgeID59': {0: nan, 3: nan},
 'JudgeID60': {0: nan, 3: nan},
 'JudgeID61': {0: nan, 3: nan},
 'JudgeID62': {0: nan, 3: nan},
 'JudgeID63': {0: nan, 3: nan},
 'JudgeID64': {0: nan, 3: nan},
 'JudgeID65': {0: nan, 3: nan},
 'JudgeID66': {0: nan, 3: nan},
 'JudgeID67': {0: nan, 3: nan},
 'JudgeID68': {0: nan, 3: nan},
 'JudgeID69': {0: nan, 3: nan},
 'JudgeID70': {0: nan, 3: nan},
 'JudgeID71': {0: nan, 3: nan},
 'JudgeID72': {0: nan, 3: nan},
 'JudgeID73': {0: nan, 3: nan},
 'JudgeID74': {0: nan, 3: nan},
 'JudgeID75': {0: nan, 3: nan},
 'JudgeID76': {0: nan, 3: nan},
 'JudgeID77': {0: nan, 3: nan},
 'JudgeID78': {0: nan, 3: nan},
 'JudgeID79': {0: nan, 3: nan},
 'JudgeID80': {0: nan, 3: nan},
 'JudgeID81': {0: nan, 3: nan},
 'JudgeID82': {0: nan, 3: nan},
 'JudgeID83': {0: nan, 3: nan},
 'JudgeID84': {0: nan, 3: nan}}

0 个答案:

没有答案