Instagram
youtube
Facebook
Twitter

Select Rows Based on a Condition in a Pandas DataFrame

Select Rows Based on a Condition in a Pandas DataFrame
      
Short Description of the Program:

This program selects rows from a Pandas DataFrame where the value in the 'Age' column is greater than 25.
      
Explanation:

  • df['Age'] > 25
    Creates a Boolean series where each value is True if the condition is met.

     
  • df[...]
    Filters the DataFrame to include only rows where the condition is True.

     

Program:

import pandas as pd

df = pd.read_csv('data.csv')

conditioned_rows = df[df['Age'] > 25]

print(conditioned_rows)