Im trying to add all data from my dataframe "tabela_proje" to a dictionary
the data frame is like this
NOME DESCRIÇÃO
0 PRO-NO-FEN FENDI
1 FORMAÇÃO NaN
2 PRO-NO-170 NaN
3 PRO-NVS-SCY STADE CHARLETY
i tried using a for loop:
for i,j in tabela_proje.iterrows():
dados = [j.to_dict()]
Im recieving this:
[{'NOME': 'PRO-NO-CBD', 'DESCRIÇÃO': nan}]
But instead of getting all data from the dataframe i only get the last row of data from the dataframe, can anyone tell what´s wrong please?!
>Solution :
IIUC, there is no need to loop here, just use a list-oriented to_dict :
out = df.to_dict(orient="list") #orient="dict" by default
Output :
print(out)
{'NOME': ['PRO-NO-FEN', 'FORMAÇÃO', 'PRO-NO-170', 'PRO-NVS-SCY'],
'DESCRIÇÃO': ['FENDI', nan, nan, 'STADE CHARLETY']}