You could use either pandas.DataFrame.loc or pandas.DataFrame.iloc. See examples below.

import pandas as pd

d = [{'a': 1, 'b': 2, 'c': 3, 'd': 4},
     {'a': 100, 'b': 200, 'c': 300, 'd': 400},
     {'a': 1000, 'b': 2000, 'c': 3000, 'd': 4000 },
     {'a': 1500, 'b': 2500, 'c': 3500, 'd': 4500}]

df = pd.DataFrame(d)

print(df)               # Print original dataframe
print(df.loc[1:2])      # Print rows with index 1 and 2, (method 1)
print(df.iloc[1:3])     # Print rows with index 1 and 2, (method 2)

Original dataframe: print(df) will print:

      a     b     c     d
0     1     2     3     4
1   100   200   300   400
2  1000  2000  3000  4000
3  1500  2500  3500  4500

And print(df.loc[1:2]) for index selection by label:

      a     b     c     d
1   100   200   300   400
2  1000  2000  3000  4000

And print(df.iloc[1:3]) for row selection by integer. As mentioned by ALollz, rows are treated as numbers from 0 to len(df):

      a     b     c     d
1   100   200   300   400
2  1000  2000  3000  4000

A rule of thumb could be:

  • Use .loc when you want to refer to the actual value of the index, being a string or integer.

  • Use .iloc when you want to refer to the underlying row number which always ranges from 0 to len(df).

Note that the end value of the slice in .loc is included. This is not the case for .iloc, and for Python slices in general.

Pandas in general

Pandas has 'easy' ways of doing all sorts of stuff like this. If you have a problem that you think is common for manipulation of tabular data, try searching for pandas ways of getting it done before inventing it yourself. Pandas will almost always have a syntactically concise and computationally faster way of doing things than what we can write ourselves.

Answer from Tim Skov Jacobsen on Stack Overflow
🌐
Pandas
pandas.pydata.org › docs › getting_started › intro_tutorials › 03_subset_data.html
How do I select a subset of a DataFrame? — pandas 3.0.6 documentation
Similar to the conditional expression, the isin() conditional function returns a True for each row the values are in the provided list. To filter the rows based on such a function, use the conditional function inside the selection brackets []. In this case, the condition inside the selection brackets titanic["Pclass"].isin([2, 3]) checks for which rows the Pclass column is either 2 or 3.
Top answer
1 of 2
10

You could use either pandas.DataFrame.loc or pandas.DataFrame.iloc. See examples below.

import pandas as pd

d = [{'a': 1, 'b': 2, 'c': 3, 'd': 4},
     {'a': 100, 'b': 200, 'c': 300, 'd': 400},
     {'a': 1000, 'b': 2000, 'c': 3000, 'd': 4000 },
     {'a': 1500, 'b': 2500, 'c': 3500, 'd': 4500}]

df = pd.DataFrame(d)

print(df)               # Print original dataframe
print(df.loc[1:2])      # Print rows with index 1 and 2, (method 1)
print(df.iloc[1:3])     # Print rows with index 1 and 2, (method 2)

Original dataframe: print(df) will print:

      a     b     c     d
0     1     2     3     4
1   100   200   300   400
2  1000  2000  3000  4000
3  1500  2500  3500  4500

And print(df.loc[1:2]) for index selection by label:

      a     b     c     d
1   100   200   300   400
2  1000  2000  3000  4000

And print(df.iloc[1:3]) for row selection by integer. As mentioned by ALollz, rows are treated as numbers from 0 to len(df):

      a     b     c     d
1   100   200   300   400
2  1000  2000  3000  4000

A rule of thumb could be:

  • Use .loc when you want to refer to the actual value of the index, being a string or integer.

  • Use .iloc when you want to refer to the underlying row number which always ranges from 0 to len(df).

Note that the end value of the slice in .loc is included. This is not the case for .iloc, and for Python slices in general.

Pandas in general

Pandas has 'easy' ways of doing all sorts of stuff like this. If you have a problem that you think is common for manipulation of tabular data, try searching for pandas ways of getting it done before inventing it yourself. Pandas will almost always have a syntactically concise and computationally faster way of doing things than what we can write ourselves.

2 of 2
1

Use this:

rowData = your_df.loc[ 'index' , : ]
🌐
Pandas
pandas.pydata.org › docs › user_guide › indexing.html
Indexing and selecting data — pandas 3.0.6 documentation
Sometimes you want to extract a set of values given a sequence of row labels and column labels, this can be achieved by pandas.factorize and NumPy indexing.
🌐
GeeksforGeeks
geeksforgeeks.org › python › selecting-rows-in-pandas-dataframe-based-on-conditions
Selecting rows in pandas DataFrame based on conditions - GeeksforGeeks
October 30, 2025 - Returns a boolean Series used to filter rows. ... Note: Always use parentheses around each condition. ... Age >= 20 and Stream in @options selects rows where Age ≥ 20 and Stream is in the Python list options.
🌐
Medium
medium.com › @whyamit101 › pandas-select-rows-by-condition-f024e58d936e
pandas select rows by condition. The biggest lie in data science? That… | by why amit | Medium
April 12, 2025 - Once you filter rows, you can simply chain the column selection: df[df['Age'] > 25]['Name']. Now that you know how to pandas select rows by condition, you’re well on your way to mastering data manipulation in Python.
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas select rows based on column values
Pandas Select Rows Based on Column Values - Spark By {Examples}
June 12, 2025 - In pandas, you can select rows based on column values using boolean indexing or using methods like DataFrame.loc[] attribute, DataFrame.query(), or
🌐
Data Science Discovery
discovery.cs.illinois.edu › guides › DataFrame-Row-Selection › selecting-rows-dataframe
Select Rows From A DataFrame - Data Science Discovery
It is possible to select rows that meet different criteria using multiple conditions by joining conditionals together with & (AND) or | (OR) logical operators. (Note: Python requires the use of parentheses around the conditionals when using ...
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › select-rows-columns-by-name-or-index-in-pandas-dataframe-using-loc-iloc
How to Select Rows & Columns by Name or Index in Pandas Dataframe - Using loc and iloc - GeeksforGeeks
November 28, 2024 - The .iloc[] method selects data based on integer positions (index numbers). It is particularly useful when you don’t know the labels but know the positions. ... Uses integer positions (0, 1, 2, ...) to index rows and columns. Just like .loc[], you can pass a range or a list of indices. Supports slicing, similar to Python lists. Unlike .loc[], it is exclusive when indexing ranges, meaning that the end index is excluded. ... import pandas as pd data = {'Name': ['Alice', 'Bob', 'Charlie'],'Age': [25, 30, 35],'City': ['New York', 'Los Angeles', 'Chicago']} df = pd.DataFrame(data) subset=df.iloc[[0,2],[1]] print(subset)
🌐
Medium
medium.com › @akaivdo › pandas-select-rows-from-a-dataframe-based-on-column-values-29aef08388ec
Pandas >> Select Rows From a DataFrame Based on Column Values | by NextGenTechDawn | Medium
May 6, 2023 - import pandas as pd # Create a sample DataFrame df = pd.DataFrame({ 'Name': ['Alice', 'Bob', 'Charlie', 'Dave', 'Eva'], 'Age': [25, 30, 35, 40, 45], 'Gender': ['F', 'M', 'M', 'M', 'F'] }) # Select rows where Age is greater than or equal to 35 result = df[df['Age'] >= 35] # Display the result print(result)
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas select rows by index (position/label)
Pandas Select Rows by Index (Position/Label) - Spark By {Examples}
November 14, 2024 - Use Pandas DataFrame.iloc[] & DataFrame.loc[] to select rows by integer Index and by row indices respectively. iloc[] attribute can accept single
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › get-a-specific-row-in-a-given-pandas-dataframe
Get a specific row in a given Pandas DataFrame - GeeksforGeeks
July 15, 2025 - Instead of manually selecting rows by index numbers, you can use logical conditions (such as greater than, less than, or equal to) to automatically identify and select the rows that meet those criteria. ... import pandas as pd data = {'Name': ['Alice', 'Bob', 'Charlie'], 'Age': [25, 30, 35], 'City': ['NY', 'LA', 'SF']} df = pd.DataFrame(data) # Select rows where City is 'NY' ny_rows = df[df['City'] == 'NY'] print(ny_rows)
🌐
Earth Data Science
earthdatascience.org › home
Select Data From Pandas Dataframes | Earth Data Science - Earth Lab
November 12, 2020 - For example, you can select all rows from the dataframe that have precipitation value greater than 2.0 inches by filtering on the precip column using the greater than > operator. # Save rows with values greater than 2.0 to new dataframe gt2_avg_monthly_precip = avg_monthly_precip[avg_monthly_precip["precip"] > 2.0] gt2_avg_monthly_precip ... Review how to download and import data files into pandas dataframe, using precip-2002-2013-months-seasons.csv which is available for download at “https://ndownloader.figshare.com/files/12710621”.
🌐
Novixys Software
novixys.com › blog › pandas-tutorial-select-dataframe
Pandas Tutorial - Selecting Rows From a DataFrame | Novixys Software Dev Blog
April 12, 2017 - Pandas recommends that for fast access of scalar values, you can use at() and iat(). With at(), you need to specify the row label for the first argument and the column name for the second.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-select-rows-from-pandas-dataframe
How to Select Rows from Pandas DataFrame? - GeeksforGeeks
July 10, 2020 - Syntax: df.loc[df['cname'] 'condition'] Parameters: df: represents data frame cname: represents column name condition: represents condition on which rows has to be selected Example 1: ... # Importing pandas as pd from pandas import DataFrame # Creating a data frame cart = {'Product': ['Mobile', 'AC', 'Laptop', 'TV', 'Football'], 'Type': ['Electronic', 'HomeAppliances', 'Electronic', 'HomeAppliances', 'Sports'], 'Price': [10000, 35000, 50000, 30000, 799] } df = DataFrame(cart, columns = ['Product', 'Type', 'Price']) # Print original data frame print("Original data frame:\n") print(df) # Selecting the product of Electronic Type select_prod = df.loc[df['Type'] == 'Electronic'] print("\n") # Print selected rows based on the condition print("Selecting rows:\n") print (select_prod) Output: Example 2:
🌐
KDnuggets
kdnuggets.com › 2019 › 06 › select-rows-columns-pandas.html
How to Select Rows and Columns in Pandas Using [ ], .loc, iloc, .at and .iat - KDnuggets
To illustrate this concept better, I remove all the duplicate rows from the "density" column and change the index of wine_df DataFrame to 'density'. To select the third row in wine_df DataFrame, I pass number 2 to the .iloc indexer.
🌐
Saturn Cloud
saturncloud.io › blog › how-to-select-rows-from-a-dataframe-based-on-list-values-in-a-column-in-pandas
How to Select Rows from a DataFrame Based on List Values in a Column in Pandas | Saturn Cloud Blog
May 1, 2026 - We used the isin() method to create a Boolean mask that indicates whether each element of a DataFrame column is contained in a list of values, and then applied this mask to the DataFrame to select the desired rows. Pandas provides many other useful methods for data manipulation and analysis, making it a powerful tool for data scientists and software engineers.
🌐
Temp Mail
tempmail.us.com › temp mail › blog › python › python: dataframe row selection based on column values
Python: DataFrame Row Selection Based on Column Values
July 24, 2024 - In addition to basic filtering with boolean indexing, Pandas provides more advanced methods for selecting rows based on column values. The query() function lets you filter DataFrame rows using SQL-like syntax. For example, you can use df.query('age > 25 and city == "New York"') to pick rows where the age is over 25 and the city is New York.
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › select-rows-from-list-of-values-in-pandas-dataframe
Select Rows From List of Values in Pandas DataFrame - GeeksforGeeks
July 23, 2025 - You can filter rows by using multiple isin() methods in combination with the AND (&) operator. This is especially helpful when you want to check multiple columns against different lists of values.