Вам нужно последнее значение в этом "списке помощников"?
Если нет, то есть код, который может оказаться полезным.
import pandas as pd
n_pos = 6
lst1 = [
[['write', 1, 1], ['bob', 1, 1], ['econom', 1, 1], ['hate', 1, 1], ['articl', 1, 1], ['mcgwier', 1, 1], ['howev', 1, 1], ['terror', 1, 1]],
[['polit', 2, 1], ['approach', 2, 1], ['correct', 2, 1], ['hate', 2, 1], ['effect', 2, 1], ['polici', 2, 1], ['stop', 2, 1], ['wors', 2, 1]],
[['support', 3, 1], ['organiz', 3, 1], ['directli', 3, 1], ['donat', 3, 1], ['right', 3, 1], ['indirectli', 3, 1], ['gay', 3, 1], ['issu', 3, 1]],
[['boycott', 4, 1], ['somebodi', 4, 1], ['appar', 4, 1], ['contradict', 4, 1], ['fund', 4, 1], ['end', 4, 1], ['reconcil', 4, 1], ['scout', 4, 1]],
[['road', 5, 1], ['saw', 5, 1], ['river', 5, 1], ['strom', 5, 1], ['research', 5, 1], ['mill', 5, 1], ['rob', 5, 1], ['ibm', 5, 1]],
[['height', 6, 1], ['yorktown', 6, 1], ['p', 6, 1], ['box', 6, 1], ['ny', 6, 1]]
]
lst2 = [(1093, 'scout', 1), (661, 'issu', 1), (379, 'econom', 1), (1154, 'somebodi', 1), (395, 'end', 1), (57, 'appar', 1), (921, 'polici', 1), (247, 'contradict', 1), (1066, 'rob', 1), (62, 'approach', 1), (259, 'correct', 1), (1061, 'right', 1), (1377, 'write', 1), (1023, 'reconcil', 1), (1232, 'terror', 1), (1208, 'support', 1), (334, 'directli', 1), (75, 'articl', 1), (381, 'effect', 1), (624, 'indirectli', 1), (140, 'bob', 1), (502, 'fund', 1), (578, 'howev', 1), (1084, 'saw', 1), (1064, 'river', 1), (1383, 'yorktown', 1), (554, 'hate', 2), (864, 'organiz', 1), (839, 'ny', 1), (356, 'donat', 1), (560, 'height', 1), (874, 'p', 1), (1192, 'stop', 1), (1195, 'strom', 1), (145, 'boycott', 1), (1051, 'research', 1), (1372, 'wors', 1), (144, 'box', 1), (922, 'polit', 1), (1065, 'road', 1), (781, 'mill', 1), (586, 'ibm', 1), (513, 'gay', 1), (757, 'mcgwier', 1)]
# we know how many cols we expect
cols = list(range(1, n_pos+1))
# we create an index from the seconds list
index = pd.MultiIndex.from_tuples((lst2), names=['id', 'name', 'temp'])
# we create an empty dataframe and fill it with zeroes
df = pd.DataFrame(columns=cols, index=index).fillna(0)
# we drop this useless last element from second list
df.index = df.index.droplevel(2)
for lst in lst1:
for el in lst:
name, col, val = el
# we dont know the id so slice(None) and the second index is the name
# thats where we set ( = val) or add ( += val) to the existing value
df.loc[(slice(None), name), col] += val
indexes = df.index.values.tolist()
values = df.values.tolist()
# we concatenate indexes and values to your desired output
desired_output = [[*idx, vals] for idx, vals in zip(indexes, values)]
, который дает
[[1093, 'scout', [0, 0, 0, 1, 0, 0]], [661, 'issu', [0, 0, 1, 0, 0, 0]], [379, 'econom', [1, 0, 0, 0, 0, 0]], [1154, 'somebodi', [0, 0, 0, 1, 0, 0]], [395, 'end', [0, 0, 0, 1, 0, 0]], [57, 'appar', [0, 0, 0, 1, 0, 0]], [921, 'polici', [0, 1, 0, 0, 0, 0]], [247, 'contradict', [0, 0, 0, 1, 0, 0]], [1066, 'rob', [0, 0, 0, 0, 1, 0]], [62, 'approach', [0, 1, 0, 0, 0, 0]], [259, 'correct', [0, 1, 0, 0, 0, 0]], [1061, 'right', [0, 0, 1, 0, 0, 0]], [1377, 'write', [1, 0, 0, 0, 0, 0]], [1023, 'reconcil', [0, 0, 0, 1, 0, 0]], [1232, 'terror', [1, 0, 0, 0, 0, 0]], [1208, 'support', [0, 0, 1, 0, 0, 0]], [334, 'directli', [0, 0, 1, 0, 0, 0]], [75, 'articl', [1, 0, 0, 0, 0, 0]], [381, 'effect', [0, 1, 0, 0, 0, 0]], [624, 'indirectli', [0, 0, 1, 0, 0, 0]], [140, 'bob', [1, 0, 0, 0, 0, 0]], [502, 'fund', [0, 0, 0, 1, 0, 0]], [578, 'howev', [1, 0, 0, 0, 0, 0]], [1084, 'saw', [0, 0, 0, 0, 1, 0]], [1064, 'river', [0, 0, 0, 0, 1, 0]], [1383, 'yorktown', [0, 0, 0, 0, 0, 1]], [554, 'hate', [1, 1, 0, 0, 0, 0]], [864, 'organiz', [0, 0, 1, 0, 0, 0]], [839, 'ny', [0, 0, 0, 0, 0, 1]], [356, 'donat', [0, 0, 1, 0, 0, 0]], [560, 'height', [0, 0, 0, 0, 0, 1]], [874, 'p', [0, 0, 0, 0, 0, 1]], [1192, 'stop', [0, 1, 0, 0, 0, 0]], [1195, 'strom', [0, 0, 0, 0, 1, 0]], [145, 'boycott', [0, 0, 0, 1, 0, 0]], [1051, 'research', [0, 0, 0, 0, 1, 0]], [1372, 'wors', [0, 1, 0, 0, 0, 0]], [144, 'box', [0, 0, 0, 0, 0, 1]], [922, 'polit', [0, 1, 0, 0, 0, 0]], [1065, 'road', [0, 0, 0, 0, 1, 0]], [781, 'mill', [0, 0, 0, 0, 1, 0]], [586, 'ibm', [0, 0, 0, 0, 1, 0]], [513, 'gay', [0, 0, 1, 0, 0, 0]], [757, 'mcgwier', [1, 0, 0, 0, 0, 0]]]