Sep-02-2019, 09:11 PM
below is a slice of the data I'm dealing with and when I try to filter out a time its always giving me an error. I don't know if it has to do with timestamp being the index and I don't want to make a new index since the data will be different size every day since there is before and aftermarket trading that may not have the same amount of trading minutes. For learning purposes, I'm trying to find the return of the last minute of a down day. If anyone has a good system of dealing with minute data it would save me a lot of time figuring it out, thanks.
print(AMZN)
print(AMZN.loc[['2019-08-05 08:16:00-04:00'], 'close'])
when I do this I get
AMZN['Datetime'] = pd.to_datetime(AMZN.index)
AMZN = AMZN.set_index(['Datetime'])
print(AMZN.loc[['2019-08-05 08:19:00-04:00'], 'close'])
print(AMZN)
Output: open high low close volume
timestamp
2019-08-05 08:16:00-04:00 1779.0000 1779.0000 1779.0000 1779.0000 880
2019-08-05 08:18:00-04:00 1778.0000 1778.0000 1778.0000 1778.0000 1377
2019-08-05 08:19:00-04:00 1778.0000 1778.0000 1777.1100 1777.1100 1172
2019-08-05 08:20:00-04:00 1777.0000 1777.8400 1777.0000 1777.7900 1128
2019-08-05 08:22:00-04:00 1780.0000 1780.0000 1778.0000 1778.0000 1296
2019-08-05 08:25:00-04:00 1778.5100 1778.5100 1778.5100 1778.5100 336
2019-08-05 08:28:00-04:00 1778.5000 1778.5000 1778.0000 1778.0000 1381
2019-08-05 08:29:00-04:00 1777.9500 1777.9500 1777.9500 1777.9500 420
print(AMZN.loc[['2019-08-05 08:16:00-04:00'], 'close'])
Output:KeyError: "None of [['2019-08-05 08:16:00-04:00']] are in the [index]"
I tried thisOutput:AMZN['Datetime'] = pd.to_datetime(AMZN.index)
AMZN = AMZN.set_index(['Datetime'])
print(AMZN.loc['2019-08-05 08:19:00-04:00'])
[output]
open 1778.00
high 1778.00
low 1777.11
close 1777.11
volume 1172.00
Name: 2019-08-05 08:19:00-04:00, dtype: float64
when I do this I get
AMZN['Datetime'] = pd.to_datetime(AMZN.index)
AMZN = AMZN.set_index(['Datetime'])
print(AMZN.loc[['2019-08-05 08:19:00-04:00'], 'close'])
Output:KeyError: "None of [['2019-08-05 08:19:00-04:00']] are in the [index]"
why is so damn hard getting the closing price in minute data.