Python Forum

Full Version: Having trouble with minute stock data
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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)
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 this
Output:
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.
I can reach the close this way but it seems very inefficient.

AMZN['Datetime'] = pd.to_datetime(AMZN.index)
AMZN = AMZN.set_index(['Datetime'])
close = (AMZN.loc['2019-08-05 08:19:00-04:00'])
print(close.at['close'])
Output:
1777.11
I observe that you have print(AMZN.loc[['2019-08-05 08:16:00-04:00'], 'close']). Shouldn't there be parentheses around 'close' as well?