Third Edit: I believe that the code can now process the data in the expected way, that is, with automation of the generation of the lists and with correct inclusion of each "Mod", regardless of the nomenclature of each string. As for the problem of irregularity of the amount of data per "Mod", I used the feature to include the data 0 in each empty field (check if this brings harm to the data processing in your case).
Room Edit: There was an error in the logic of this last posted version, I will resend the version that I believe is working properly. To better organize the answer, I will replace the previous versions with the code below:
import pandas as pd
dados = {}
l = []
lista_mods = []
lista_valores = []
maximo = 0
l.append(('Mod1',0,70))
l.append(('Mod1',1,88))
l.append(('Mod1',2,97))
l.append(('Mod1',3,44)) # linha incluída para testar o funcionamento com diferentes quantidades de índices
l.append(('Mod2',0,44))
l.append(('Mod2',1,93))
l.append(('Mod2',2,100))
l.append(('Mod3',0,99))
l.append(('Mod3',1,71))
l.append(('Mod3',2,33))
for pos, c in enumerate(l):
if l[pos][0] not in lista_mods:
lista_mods.append(l[pos][0])
for pos, c in enumerate(lista_mods):
for n in range(0, len(l)):
if l[n][0] == c:
lista_valores.append([])
lista_valores[pos].append(l[n][2])
for c in lista_valores:
if len(c) > maximo:
maximo = len(c)
for pos, c in enumerate(lista_valores):
while True:
if len(c) < maximo:
lista_valores[pos].append(0)
else:
break
dados = dict(zip(lista_mods, lista_valores))
df = pd.DataFrame(dados)
print(df)
df.to_html('temp.html')
I don’t understand what’s wrong
– Evilmaax
Hello, I edited the question to show how it’s getting the way I did.
– Core