Python Forum
Having trouble with minute stock data
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Having trouble with minute stock data
#1
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.
Reply
#2
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
Reply
#3
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?
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Create simple live plot of stock data dram 2 2,913 Jan-27-2023, 04:34 AM
Last Post: CucumberNox
  Exporting Stock Fundamental Data to a CSV file with yahoo_fin DustinKlent 2 4,717 Aug-01-2022, 06:08 PM
Last Post: paulyan
  SMA (simple moving avg) Not receiving Data (stock prices). gdbengo 2 1,441 Jul-31-2022, 08:20 PM
Last Post: paulyan
  Yfinance - Intraday stock data with yf.download diogo_80 2 5,962 Apr-29-2022, 05:07 AM
Last Post: processingclouds
  odd or even minute Dixon 12 8,657 Dec-31-2019, 09:02 AM
Last Post: Larz60+
  Trouble with encoded data (I think) fishglue 0 1,798 Oct-10-2019, 08:15 PM
Last Post: fishglue
  python crontab remove_all(comment="Minute*") vvarrior 1 2,770 Aug-06-2018, 12:39 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020