
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python Pandas - How to select rows from a DataFrame by integer location
To select rows by integer location, use the iloc() function. Mention the index number of the row you want to select.
Create a DataFrame −
dataFrame = pd.DataFrame([[10, 15], [20, 25], [30, 35]],index=['x', 'y', 'z'],columns=['a', 'b'])
Select rows with integer location using iloc() −
dataFrame.iloc[1]
Example
Following is the code −
import pandas as pd # Create DataFrame dataFrame = pd.DataFrame([[10, 15], [20, 25], [30, 35]],index=['x', 'y', 'z'],columns=['a', 'b']) # DataFrame print"DataFrame...\n",dataFrame # select rows with loc print"\nSelect rows by passing label..." print(dataFrame.loc['z']) # select rows with integer location using iloc print"\nSelect rows by passing integer location..." print(dataFrame.iloc[1])
Output
This will produce the following output −
DataFrame... a b x 10 15 y 20 25 z 30 35 Select rows by passing label... a 30 b 35 Name: z, dtype: int64 Select rows by passing integer location... a 20 b 25 Name: y, dtype: int64
- Related Articles
- Python Pandas - How to select multiple rows from a DataFrame
- Python Pandas - How to select rows from a DataFrame by passing row label
- Python Pandas - Select a subset of rows from a dataframe
- Python - How to select a column from a Pandas DataFrame
- Select rows from a Pandas DataFrame based on column values
- Use a list of values to select rows from a Pandas DataFrame
- Python Pandas – How to select DataFrame rows on the basis of conditions
- Python - How to drop the null rows from a Pandas DataFrame
- Python - Select multiple columns from a Pandas dataframe
- Python Pandas - How to append rows to a DataFrame
- Select DataFrame rows between two index values in Python Pandas
- Python - Drop specific rows from multiindex Pandas Dataframe
- Python - How to select a subset of a Pandas DataFrame
- Python Pandas - Display specific number of rows from a DataFrame
- Python - Ranking Rows of Pandas DataFrame

Advertisements