code:
i = 0
while i<3:
def avoid_repeat_df():
rows = []
for i in range(1):
try:
rows. append([i, i + 2])
df = pd. DataFrame(rows, columns=["Aaa", "Bee"])
df.to_csv('example.csv')#mode='a' write the ouput same as df else only last occurance
print(df)
except:
pass
avoid_repeat_df()
i+=1
it prints output as
Aaa Bee
0 0 2
Aaa Bee
0 0 2
Aaa Bee
0 0 2
But in csv only last line writes (in append mode same as df output all the line)
What i expect : avoid repeating column header
Aaa Bee
0 0 2
0 0 2
0 0 2
Hope i explained in details. Thanks for your time and help.