I use the following to write CSV lines in a loop while running sensor instrumentation, and I want to read them back in for post-processing without pandas. I would like to use the imported data to plot, and do basic arithmetic on the time stamp column, e.g. calculate time separation between events captured by a sensor.
from datetime import datetime
date_time = datetime.now()
filename.write(str(date_time)+','+str(SensorData1)+','+str(SensorData2))
Each line of the CSV output looks like this:
2025-06-01 19:05:24.384927,8.001,4.999
The link suggested here: How do I read and write CSV files? does not automatically deal with datetime.now() formats.
As written to CSV, datetime.now() is a quasi-numerical value that can be used for plotting by matplotlib. So, I am not interested in importing the datetime.now() data from CSV as a string, or some other object, but as one where I can do basic math and use numpy to calculate time-increments between each sensor reading value.
csvpackage for reading and writing csv files. You might also want to check outdatetime.datetime.strptime()now(). However, you might consider making your own object that contains each time and sensor data elements then usepickleto write and read those objects...