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.
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.
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.
- Get a list of a specified column of a Pandas DataFrame
- Get a specific row in a given Pandas DataFrame
- Select row with maximum and minimum value in Pandas dataframe
- Extract date from a specified column of a given Pandas DataFrame using Regex
- How to display bar charts in Pandas dataframe on specified columns?
- Convert given Pandas series into a dataframe with its index as another column on the dataframe
- Insert row at given position in Pandas Dataframe
- Python | Pandas DataFrame.fillna() to replace Null values in dataframe
- Pandas Dataframe.to_numpy() - Convert dataframe to Numpy array
- Python | Change column names and row indexes in Pandas DataFrame
- Apply function to every row in a Pandas DataFrame
- Add a row at top in pandas DataFrame
- Select any row from a Dataframe in Pandas | Python
- Select any row from a Dataframe using iloc and iat in Pandas
- How to Sort a Pandas DataFrame based on column names or row index?
- Apply a function to each row or column in Dataframe using pandas.apply()
- How to add one row in an existing Pandas DataFrame?
- How to get column and row names in DataFrame?
- Get all rows in a Pandas DataFrame containing given substring
- Get column index from column name of a given Pandas DataFrame
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.