Get the specified row value of a given Pandas DataFrame
Pandas DataFrame is a two-dimensional size-mutable, potentially heterogeneous tabular data structure with labeled axes (rows and columns).
Now let’s see how to get the specified row value of a given DataFrame.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course
We shall be using loc[ ], iloc[ ], and [ ] for a data frame object to select rows and columns from our data frame.
- iloc[ ] is used to select rows/ columns by their corresponding labels.
- loc[ ] is used to select rows/columns by their indices.
- [ ] is used to select columns by their respective names.
Method 1: Using iloc[ ].
Example: Suppose you have a pandas dataframe and you want to select a specific row given its index.
Method 2: Using loc[ ].
Example: Suppose you want to select rows where the value of a given column is given.
Method 3: Using [ ] and iloc[ ].
Example: Suppose you want only the values pertaining to specific columns of a specific row.