Load data
import yfinance as yyticker = yf.Ticker("MSFT")data = yticker.history(period="1y")print(data)
Open High ... Dividends Stock Splits
Date ...
2019-11-29 150.505606 150.703506 ... 0.0 0
2019-12-02 150.218634 150.238429 ... 0.0 0
2019-12-03 145.943929 147.863580 ... 0.0 0
2019-12-04 148.566128 148.605702 ... 0.0 0
2019-12-05 148.477105 148.744279 ... 0.0 0
... ... ... ... ... ...
2020-11-20 212.199997 213.289993 ... 0.0 0
2020-11-23 210.949997 212.289993 ... 0.0 0
2020-11-24 209.589996 214.250000 ... 0.0 0
2020-11-25 215.110001 215.289993 ... 0.0 0
2020-11-27 214.850006 216.270004 ... 0.0 0
Get row position of index
# get index of 3rd rowindex = data.index[2] # Timestamp('2019-12-03 00:00:00')# get row position of indexrow_index = data.index.get_loc(index) # 2
row_index = data.index.get_loc('2019-12-03') # 2