简体   繁体   中英

How to update instead of rewriting csv by python with pandas?

Every day I'm scraping a CSV file from the web and updating a CSV file in my system. How do I update the CSV file? I don't want to create a new CSV file every day, I just need to update one CSV file?. Before that, I need to remove previous days data so that I don't have duplicate data in 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM