How to Select Rows from Pandas DataFrame? Last Updated : 10 Jul, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report pandas.DataFrame.loc is a function used to select rows from Pandas DataFrame based on the condition provided. In this article, let's learn to select the rows from Pandas DataFrame based on some conditions. 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: Python3 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: Python3 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 HomeAppliances Type select_prod = df.loc[df['Type'] == 'HomeAppliances'] print("\n") # Print selected rows based on the condition print("Selecting rows:\n") print (select_prod) Output: Example 3: Python3 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 Price greater # than or equal to 25000 select_prod = df.loc[df['Price'] >= 25000] print("\n") # Print selected rows based on the condition print("Selecting rows:\n") print (select_prod) Output: Example 4: Python3 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, 30000, 30000, 799] } df = DataFrame(cart, columns = ['Product', 'Type', 'Price']) # Print original data frame print("Original data frame:\n") print(df) # Selecting the product of Price not # equal to 30000 select_prod = df.loc[df['Price'] != 30000] print("\n") # Print selected rows based on the condition print("Selecting rows:\n") print (select_prod) Output: Comment More infoAdvertise with us Next Article How to Randomly Select rows from Pandas DataFrame U utkarsh_kumar Follow Improve Article Tags : Python Python-pandas Python pandas-dataFrame Practice Tags : python Similar Reads How to Randomly Select rows from Pandas DataFrame In Pandas, it is possible to select rows randomly from a DataFrame with different methods. Randomly selecting rows can be useful for tasks like sampling, testing or data exploration.Creating Sample Pandas DataFrameFirst, we will create a sample Pandas DataFrame that we will use further in our articl 3 min read How to select a range of rows from a dataframe in PySpark ? In this article, we are going to select a range of rows from a PySpark dataframe. It can be done in these ways: Using filter().Using where().Using SQL expression. Creating Dataframe for demonstration: Python3 # importing module import pyspark # importing sparksession from pyspark.sql module from pys 3 min read How to Get First Row of Pandas DataFrame? To get the first row of a Pandas Dataframe there are several methods available, each with its own advantages depending on the situation. The most common methods include using .iloc[], .head(), and .loc[]. Let's understand with this example:Pythonimport pandas as pd data = {'Name': ['Alice', 'Bob', ' 4 min read Select any row from a Dataframe in Pandas | Python In this article, we will learn how to get the rows from a dataframe as a list, without using the functions like ilic[]. There are multiple ways to do get the rows as a list from given dataframe. Letâs see them will the help of examples. Python3 # importing pandas as pd import pandas as pd # Create t 1 min read Select Pandas dataframe rows between two dates Prerequisites: pandas Pandas is an open-source library that is built on top of NumPy library. It is a Python package that offers various data structures and operations for manipulating numerical data and time series. It is mainly popular for importing and analyzing data much easier. Pandas is fast a 2 min read How to Get Cell Value from Pandas DataFrame? In this article, we will explore various methods to retrieve cell values from a Pandas DataFrame in Python. Pandas provides several functions to access specific cell values, either by label or by position.Get value from a cell of Dataframe using loc() functionThe .loc[] function in Pandas allows you 3 min read Like