0

I develop data analysis app with Python. The data in the file is deleted when I add data to it again when I do df.to_excel. How can I add new data to the excel file while preserving other data Thanks,

sorry for my bad english

I used This code for add data

def ageGroup(city,age,period):
 ....
 df.to_excel('test.xlsx')
 ...

for i in range(len(city_list)):
for j in range(len(age_list_)):
    ageGroup(city_list[i], age_list_[j], 22)
1

1 Answer 1

1

Have you looked at these parameters from the to_excel method ?

startrow : int, default 0
Upper left cell row to dump data frame.

startcol : int, default 0
Upper left cell column to dump data frame.

You could open your data, get the length of it, and write more starting at the length of your data +1.

Sign up to request clarification or add additional context in comments.

1 Comment

This is not happening either. I did startrow = 0 and I increased the startrow variable len (df) +1 in each loop. Didn't add under

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.