[英]How to update instead of rewriting csv by python with pandas to fetch stock data?
[英]How to update instead of rewriting csv by python with pandas?
每天我都在從 web 中抓取 CSV 文件,並在我的系統中更新 CSV 文件。 如何更新 CSV 文件? 我不想每天都創建一個新的 CSV 文件,我只需要更新一個 CSV 文件? 在此之前,我需要刪除前幾天的數據,以免 CSV 中的數據重復。
f = open("data.csv", "w+") # deletes the old content in your csv file (all content) f.close() your_work=True while your_work: new_df=pd.read_csv("new.csv") # add your new datas from web or file etc new_df.to_csv('data.csv', mode='a', header=False) #append mode("a") saves the df data to your csv file line by line your_work=False
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.