0

I am working on parsing stock data. below is the data i need but the attribute seems to change based on whatever stock i am looking at. is there a way to make 'AAPL' a variable here so that i can just input my symbol there or is there a better way of getting this information out of the df?

print(opening_range_bars.AAPL['close'])
time
2021-05-14 14:00:00-04:00    127.180
2021-05-14 14:01:00-04:00    127.210
2021-05-14 14:02:00-04:00    127.210
2021-05-14 14:03:00-04:00    127.220
2021-05-14 14:04:00-04:00    127.240
                              ...   
2021-05-14 15:36:00-04:00    127.295
2021-05-14 15:37:00-04:00    127.305
2021-05-14 15:38:00-04:00    127.295
2021-05-14 15:39:00-04:00    127.345
2021-05-14 15:40:00-04:00    127.355

without .AAPL

print(opening_range_bars)
                              AAPL                                  
                              open     high      low    close volume
time                                                                
2021-05-14 14:00:00-04:00  127.210  127.230  127.150  127.180   2729
2021-05-14 14:01:00-04:00  127.200  127.210  127.200  127.210    667
2021-05-14 14:02:00-04:00  127.220  127.245  127.210  127.210   1852
2021-05-14 14:03:00-04:00  127.210  127.220  127.185  127.220   3941
2021-05-14 14:04:00-04:00  127.230  127.250  127.225  127.240   5282
                            ...      ...      ...      ...    ...
2021-05-14 15:36:00-04:00  127.330  127.330  127.260  127.295   1665
2021-05-14 15:37:00-04:00  127.285  127.320  127.285  127.305   4406
2021-05-14 15:38:00-04:00  127.305  127.320  127.270  127.295   2540
2021-05-14 15:39:00-04:00  127.305  127.350  127.295  127.345  12972
2021-05-14 15:40:00-04:00  127.355  127.380  127.345  127.355   3010
[101 rows x 5 columns]

1 Answers1

0

You can access it using brackets.

opening_range_bars['AAPL']['close']

Then just replace AAPL with a variable.

James
  • 32,991
  • 4
  • 47
  • 70