How do I save a date input from csv as a variable PYTHON

Viewed 24

I need my program to take one cell in a csv that is a date and save it as a variable, then read the next cell in the column and save it as the next variable. The rest of the program does a calculation with the dates, but i am not sure how to save each date as a variable. (The part that is commented out is what it would look like if a user did the input themsef, but I would like it read in from the csv) enter image description here

1 Answers

You can convert csv to numpy with:

from numpy import genfromtxt
my_data = genfromtxt('my_file.csv', delimiter=',')

And then you can just iterate through the created array to get the elements. Be careful as how the delimiter is defined, here it's a coma, sometimes there isn't any, so just make sure you know how your csv data are delimited.

Related