Here I want to read time in 24 hours format include in csv file. I wrote the class to convert time in format %H:%M:%S
. but I got an error
'list' object has no attribute 'strptime'
Can anyone help to solve this? Here I post my code.
import pandas as pd
import time
import datetime
def convertTime(s):
tm = time.strptime(s, "%H:%M:%S")
return datetime.datetime.strptime(tm.tm_hour, tm.tm_min, tm.tm_sec)
data = pd.read_csv('x.csv')
row_num = 0
for row in data:
if(row_num == 0):
time.append(convertTime(row[0]))
Here is subset of my csv file
time g
6:15:00 141
9:00:00 0
9:25:00 95
9:30:00 0
11:00:00 149
Does this achieve what you want?
df['time'] = pd.to_datetime(df['time'], format='%H:%M:%S').dt.time
df.set_index('time', inplace=True)
# plotting
df.plot()