Course Name: Python for Trading: Basic, Section No: 8, Unit No: 17, Unit type: Quiz
In this question, the correct answer is provided as a) having rows 0,1,2,3,4 while the expression is
df.loc[:4, 'Closing Price]
here the 4 usually means it is up to but not including 4, so the correct answer should be c) which only has rows 0 to 3
Thanks to cross check and correct
Regards
Mohamed
Hey Mohamed,
Thanks for communicating your doubt.
I think that are confused between the two pandas functions .loc() and .iloc().
If you go through the notebook on Indexing & Missing Values,
In the section covering Indexing using .loc(), you will find that we have covered a very similar exercise.
Here's an image of the code snippet from the same notebook:

Similarly, here is another cell that covers Indexing using .iloc() from the notebook.

As you might have noticed from the above two examples, when we use .loc(), both the start and stop of the slice are included. But while using .iloc(), since it is index-based, the stop value will not be included.
To learn more in detail, about the differences between .loc() and .iloc(), you can check out this link.
I hope this helped in clarifying your doubt.