Reputation: 53
I am trying to compare time values with DateTime.
open_time = datetime.time(6,30,00)
close_time = datetime.time(13,00,00)
list_of_time = [data_S['hour']]
data_S is just a Pandas DataFrame and I am converting the hour column into a list.
list_of_time printed looks like this:
[0 04:00:00
1 04:01:00
2 04:02:00
3 04:03:00
4 04:04:00
...
1515 16:55:00
1516 16:56:00
1517 16:57:00
1518 16:58:00
1519 16:59:00
Name: hour, Length: 1520, dtype: object]
I have this for loop to check if the time in the list is less than open_time
for i in list_of_time:
if i < open_time:
print (I)
I am getting this error when I run the file and I do not understand what the error is telling me.
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Upvotes: 1
Views: 120
Reputation: 54718
I believe you need to be doing:
list_of_time = data_S['hour'].tolist()
When you fetch a pandas column like this, it isn't just a simple list of numbers. tolist
will do that.
Upvotes: 1