Swaraj
Swaraj

Reputation: 1

datetime format for processing a CSV file

I am processing a CSV file. So the format in my CSV file is: 2020-10-26T03:45:00Z (example).

How do I read this format to process the entire Excel sheet? for eg: for a date, we can time = datetime.strptimerow[0],'%Y/%d/%m')

How can I use it similarly for my given format? here is the snippet:

with open('nifty.csv') as database:
file = open('nifty.csv', newline='')
reader = csv.reader(file)
header = next(reader)
data = []
for row in reader:
    # row = [time,open,high,low,close]
    time = datetime.strptime(row[0],'%Y-%d-%m')  ##here is where i get 
    stuck coz i need the right format according to the example given 
    above.##
    open_price = float(row[1]) 
    high = float(row[2])
    low = float(row[3])
    close = float(row[4])

format required 2020-10-26T03:45:00Z year,month,day,hour,minutes,zone

Upvotes: 0

Views: 618

Answers (1)

Nicoowr
Nicoowr

Reputation: 809

You can use parse from dateutil package:

from dateutil.parser import parse
parse("2020-10-26T03:45:00Z")

Output:

datetime.datetime(2020, 10, 26, 3, 45, tzinfo=tzutc())

Upvotes: 1

Related Questions