Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
263 views
in Technique[技术] by (71.8m points)

Connect Excel worksheet to CSV using Python Pandas

I have written a Python code (below) that reads a self-updating, real-time Excel (.xlsm) and converts it into a CSV every 1 second. But the code doesn't seem to overwrite the previous excel with the newer one, which it should do. Am I missing something?

My ultimate goal is to sync the Excel with the CSV so that all relative changes in Excel reflects in the CSV in real-time. Any help/suggestions on it would be highly appreciated.

import pandas as pd
import time
from timeloop import Timeloop
from datetime import timedelta

tl = Timeloop()
excel_file_path='I:/Live Stats/Corona.xlsm'
csv_file_path ='N:/My Drive/Corona_Live.csv'
primaryexcelsheet='Stats'         
read_Excelfile =pd.read_excel(excel_file_path,sheet_name=primaryexcelsheet)

@tl.job(interval=timedelta(seconds=1))
def sample_job_every_1s():
    def format_csv(excel_file_path,csv_file_path):
        read_Excelfile =pd.read_excel(excel_file_path,sheet_name=primaryexcelsheet)
        read_Excelfile.to_csv(csv_file_path,index=None,header=True)
    format_csv(excel_file_path,csv_file_path)

if __name__ == "__main__":
    tl.start(block=True)
question from:https://stackoverflow.com/questions/65623620/connect-excel-worksheet-to-csv-using-python-pandas

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...