Error Indexing using .loc()

Dear all. In an env with python 3.7, pandas 1.3.0 and jupyter lab 3.0.16, I try to reproduce some of the sentences shown in the Indexing & Missing Values section, in the Pands section, included in the Indexing & Missing values notebook of the course " Python for Trading Basic ". On your notebook, the sentences operate correctly. I try to reproduce them on my notebook, as follows.

 

import pandas as pd
from pandas_datareader import data
data = data.get_data_yahoo('AAPL', '2021-01-01', '2021-06-01')

print(data.loc[:, ['Close', 'Open']])

print(data.loc[:4, ['Close', 'Open']])

TypeError: cannot do slice indexing on DatetimeIndex with these indexers [4] of type int

 

The error is mine when I did not realize that the index of the DataFrame used in the course is numeric and therefore, 0 and four are two indexes, not two positions, while in the DataFrame that I use, the indexes are dates.