Tuesday, May 25, 2021

Operate on DataFrame Part-2

 

Dataframe attributes - Part 2

WE WILL USE NEW EXAMPLE FROM HERE.

 

6.new_data_frame.iat[] use to access(get or set) single value at

 [row index,column index]

 

Here, in new_data_frame.iat[0,2]  0 is row index, 2 is country.

0th index=name

1st index=rank

2nd index=country.

 

7.new_data_frame.iloc[] result differs with the various type of inputs passed. 

        a) an integer - returns the entire row at specified integer(index value) along with column.

 

 

 

        b)list of integersnew_data_frame.iloc[[0,1]] returns rows in 0th and 1st index.

 

 

        c)Using slicing operator - new_data_frame.iloc[1:3] returns data in rows 1 and 2.

 

 

         d)A list of boolean values matching length of dataframe -

 Here length is 3, new_data_frame.iloc[[True,False,True]].

 Now, 0th row and 2nd row will be printed.

 

 

        e)Using lambda function - using lambda function.

 

 

       f) Using double indexing - Access the value with row and column index.

 

 

8. new_data_frame.index - returns the row labels.

 

 

9. new_data_frame.loc - returns the mentioned row or rows.

 

 

10. new_data_frame.ndim - returns the array dimension of dataframe.

 

 

11. new_data_frame.size - returns the size of number of elements in dataframe.

 

 

12.new_data_frame.shape - returns the shape of dataframe.

 

3 rows and 4 columns in new_data_frame.


13.new_data_frame.style - styles the dataframe using html and css.

 

 

14. new_data_frame.to_numpy - changes elements to numpy array.

 

 

If you have come this far. You did a great job!

 

No comments:

Post a Comment

Anaconda Installation

In this post we will discuss about Anaconda and its installation. Anaconda comes with number of applications(jupyter notebook included), dat...