Starting with a pandas Dataframe with datetimes as the index, I create 2 lists:
- datetimes of all rows
- dates of all rows
My code below works but is slow. Is there a faster way of doing this? I have tried multiple approaches but all are slow.
dateTimeFormat = '%Y-%m-%dT%H:%M:%S'
barDates = []
barDateTimes = []
for numpyDatetime64 in bars.index.values: # 'bars' is a pandas dataframe
dateTime = datetime.datetime.strptime(str(numpyDatetime64).split('.')[0], dateTimeFormat)
date = dateTime.date()
barDateTimes.append(dateTime)
barDates.append(date)
Per Andrej's suggestion, here is an example of the input dataframe:
A B C ... T U V
dateTime ...
2010-05-13 09:31:00 117.130 117.240 117.13 ... 121.2400 121.2500 172429.0
2010-05-13 09:32:00 117.180 117.220 117.16 ... 121.1800 121.2700 98480.0
2010-05-13 09:33:00 117.200 117.280 117.19 ... 121.2701 121.3100 41255.0
2010-05-13 09:34:00 117.200 117.220 117.01 ... 121.2700 121.3999 250893.0
2010-05-13 09:35:00 117.100 117.130 116.83 ... 121.2500 121.2505 69952.0
... ... ... ... ... ... ... ...
2019-10-04 15:56:00 294.330 294.560 294.33 ... 141.7713 141.7800 15407.0
2019-10-04 15:57:00 294.550 294.630 294.50 ... 141.7750 141.7900 16815.0
2019-10-04 15:58:00 294.515 294.520 294.40 ... 141.7950 141.8700 39316.0
2019-10-04 15:59:00 294.485 294.530 294.38 ... 141.8600 141.8800 46623.0
2019-10-04 16:00:00 294.515 294.515 294.31 ... 141.8500 141.9300 89639.0
.tolist()at the end.