How to add values in excel in python

Asked

Viewed 157 times

-1

Good afternoon, I am trying to add values in excel spreadsheet that is creating inside the program, the problem is that when the loop comes back, it does not add but it replaces what was already in the file.

    # 1. Responsável Técnico
tab = driver.find_element_by_id('tab_profissional')
dados1 = tab.find_elements_by_tag_name('b')
tabela.append(art)
for box in dados1: tabela.append(box.text)
df = pd.DataFrame(tabela).T
df.columns = ['ART', 'Nome Responsavel', 'Título profissional', 'RNP', 'Registro', 'Empresa contratada']


writer = pd.ExcelWriter('Responsável Técnico.xlsx')
df.to_excel(writer, 'Planilha', index=False)
writer.save()

I had even managed otherwise, he just kept everything on the same line.

1 answer

0

You need to set the way as append(mode='a')

 writer = pd.ExcelWriter('Responsável Técnico.xlsx', mode='a')
        df.to_excel(writer, 'Planilha', index=False)
        writer.save()

Browser other questions tagged

You are not signed in. Login or sign up in order to post.