2

I am importing a stock data frame and trying to select the first index. When I try to select it, It comes up empty. Here is the data frame

         RPAI                               
                             open    high     low   close volume
time                                                            
2021-04-14 15:50:00-04:00  10.960  10.960  10.950  10.950    800
2021-04-14 15:52:00-04:00  10.940  10.940  10.940  10.940    200
2021-04-14 15:53:00-04:00  10.935  10.935  10.935  10.935    414
2021-04-14 15:55:00-04:00  10.930  10.930  10.930  10.930    203
2021-04-14 15:56:00-04:00  10.935  10.935  10.935  10.935    400
2021-04-14 15:58:00-04:00  10.935  10.935  10.935  10.935    164
2021-04-14 15:59:00-04:00  10.935  10.940  10.935  10.940    550

Then select the first selection of the close to create a limit price:

limit_price = after_opening_range_breakdown.iloc[0][(symbol, 'close')]
print('Limit price',limit_price)

Then I get this error:

raise IndexError("single positional indexer is out-of-bounds") IndexError: single positional indexer is out-of-bounds

How do I select the first closing price of 10.950?

2
  • what is this 'symbol' variable do? Commented Apr 15, 2021 at 5:55
  • The symbol is the stock symbol. The columns are formatted (symbol, column name) Commented Apr 15, 2021 at 6:05

1 Answer 1

1

You can select the first index of column 'close' as below:

limit_price = after_opening_range_breakdown['close'].iloc[0]

for example: if df1 contains the stock data df['close'].iloc[0] should work

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

I get this error: raise KeyError(key) from err KeyError: 'close'
what is the name of the data frame variable which contains stock data? That variable_name['close'].iloc[0] will give you the first index. I assumed "after_opening_range_breakdown" is that variable name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.