0

I have a CSV file and want to Write data from CSV file to XLS file. But here is the tricky part, a new CSV file gets generated after few seconds and again I need to write the CSV data into the same Excel file that has been already generated, but now the new data will be added into new row.

This is not an homework Assignment, I have a Machine Which is generating a new csv file after few seconds. And I want my Excel sheet to be updated with the new file CSV data.

I am looking for solution or partial solution in python.

Thank you

2
  • Is it an long running process where a csv is generated every few seconds ? Commented Mar 19, 2019 at 20:48
  • It gets generated into a directory, I came to know that there is an API Watchdog that can look for new files generated. And yeah the CSV keep on getting generated till I dont shutdown the machine. Commented Mar 19, 2019 at 20:55

1 Answer 1

2

Generally speaking, the workflow will probably be something like this using pandas:

new_data = pandas.read_csv('new_data.csv', header=0)
all_data = pandas.read_excel('file://excel_file.xlsx')
combined = all_data.append(new_data)
combined.to_excel('excel_file.xlsx')

Of course you may need to mess with some of the parameters to match up everything with your data, and possibly have this looping so it is always getting the latest changes and adding them.


Useful docs that will assist:

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

13 Comments

Thank you for the response, but I don't want to do this tedious task of appending all data again and again. I am looking for something Where only the existing Excel file is appended with new data only.
@ViralParmar Could you please explain what you mean? This reads the existing excel file and appends the new data from the CSV? Does the CSV contain all the data as well but has new rows added every few seconds?
Every time a new CSV is generated with Few rows, and I want those new rows to be appended to my existing XLS file.
@ViralParmar Right, these four lines of code could be called every time that the API Watchdog notices a new CSV file. Since the CSV only contains new rows, and the excel sheet (which you can keep writing over) has everything prior, the append will only add those new rows, and it would save be saved as an excel file with the same name.
Do you have any idea of what to do with the header in each CSV file? I mean I only need data. I dont want header again and again from the newly generated CSV file . Header as in Column name.
|

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.