iloc

Suppose you have a dataframe as the one given below:

let us call this dataframe ‘var’

What would you do, if you want to extract the data from the first row-second column?

You would use iloc.

Let me explain you how.

Here, by default he numerical location values of the rows and columns start with zero. This means, the location value of first row is ‘0’ and first column is ‘0’

row 1 = 0 , row 2 = 1 , row 3 = 2 ,…………………… row n = n-1

column 1 = 0 , column 2 = 1 , column 3 = 2 ,…………………… column n = n-1

So, if you want the value of row1,column1 you’ll have to use the following syntax:

This will display the following result:

If you want to value of row3, column2 use the following :

This will display the following result:

Consider the following code:

Here, you create a dataframe of all the intraday prices of a particular stock.

So, what would you do if you want to get the latest price.

If you execute the code above you will get the following result:

This happens if you print the entire dataframe. But we don’t want that, you just want the latest price. So, we will use ‘iloc’

This will give you the latest price of the stock.

 

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *