0

I'm trying to write a dictionary into an excel file:

import pandas as pd
d_bsp = {"Datum":"24.03.2020", "Anz.": 5, \
         "Steuerung":"XY", "Test":"XY", "Auftrag":"1999080",  \
         "Fehlermeldung":"Error","Toleranzbereich":440,"Bauteil":"R80", \
         "Artikelnummer":"120-0170114", "Ursache":"Shortcut", \
         "Verursacher":"THT", "Reparatur":"Bauteil löten"}

df = pd.read_excel("Fehlererfassung.xlsx")
df = df.append(d_bsp, ignore_index = True)
df.to_excel("Fehlererfassung.xlsx")

The problem: It always puts new Columns into my existing excel file.

The excel file has this columns:

Datum, Anz., Steuerung, Test, Auftrag, Fehlermeldung, Toleranzbereich, Bauteil, Artikelnummer, Ursache, Verursacher, Reparatur

And if I start the code, the existing excel file looks like:

Unnamed 0, Datum, Anz., Steuerung, Test, Auftrag, Fehlermeldung, Toleranzbereich, Bauteil, Artikelnummer, Ursache, Verursacher, Reparatur

What is the problem?

Thank you.

2 Answers2

0

Can you try setting index=False in the to_excel?

df = pd.read_excel("Fehlererfassung.xlsx")
df = df.append(d_bsp, ignore_index = True)
df.to_excel("Fehlererfassung.xlsx",index=False)
Anthony1223
  • 351
  • 2
  • 7
0

Without seeing sample data, my best guess is that you are output the index as well, which might or might not be the "unnamed 0" column.

If that is the problem try this:

df.to_excel("Fehlererfassung.xlsx", index=False)
Andreas
  • 8,694
  • 3
  • 14
  • 38