0

Permanently updating .csv files

Hello everyone. I'm working on a python code that samples something similar to a smart fridge. Each time the code is running, it stores in specific variables/vectors data about the food currently stored from a .csv file and uses them to do its work. My problem is that I can't find a way to update that file with new information, such as substituting a specific value for consumption or storage, or creating or deleting lines if a new element runs out or gets bought. All I managed to do was appending to the last line. Can anybody help?

16th Oct 2021, 2:41 PM
Edoardo Blanco
Edoardo Blanco - avatar
2 Réponses
+ 3
Use the pandas module. Import the data, work with it and then save it using the .to_csv() method. https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_csv.html
16th Oct 2021, 2:51 PM
Simon Sauter
Simon Sauter - avatar
0
Simon Sauter thx, I'll try it rn
16th Oct 2021, 2:53 PM
Edoardo Blanco
Edoardo Blanco - avatar