Update data from two worksheets without overwriting in the source file

Asked

Viewed 83 times

0

I read the file sheets in the following way:

sheet_Pessoas = pd.read_excel("meus_dados.xlsx", sheet_name=0)
sheet_Clientes = pd.read_excel("meus_dados.xlsx", sheet_name=1)

Then I add a line in the Dataframe of each sheet that way:

sheet_Pessoas.loc[-1] = [Nome,int(CPF),int(Idade),int(Nasc),Login,Senha,Cargo]  # adding a row
        with pd.ExcelWriter("meus_dados.xlsx") as writer:
            sheet_Pessoas.to_excel(writer, sheet_name = 'Pessoas', index = False)

sheet_Clientes.loc[-1] = [Empresa,int(CNPJ),Resp,Login,Senha]  # adding a row
        with pd.ExcelWriter("meus_dados.xlsx") as writer:
            sheet_Clientes.to_excel(writer, sheet_name = 'Clientes', index = False)

But when I save the spreadsheet in the same file, it overwrites all existing spreadsheets. If I have the spreadsheet Pessoas and Clientes and I want to update the spreadsheet Clientes, when saved in the same file meus_dados only the spreadsheet appears Clientes, the spreadsheet Pessoas was superscripted.

I wonder how I can update my file sheets without them overwriting.

1 answer

0

Excelwriter supports append mode:

with pd.ExcelWriter("meus_dados.xlsx", mode='a') as writer:
  • I have tried, does not support this mode. I use Spyder in version 2.

Browser other questions tagged

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