Selecting index from data frame

Viewed 44

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?

1 Answers

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

Related