Filter CSV Rows by Column Value in Python

Learn how to read a CSV file and filter rows based on specific column values using Python's pandas library.

By Cojocaru David29d ago (Dec 19, 2025)
data manipulation
csv
pandas

Filter CSV Rows by Column Value in Python

python
import pandas as pd

def filter_csv_by_column_value(file_path, column_name, filter_value):
    # Read the CSV file into a DataFrame
    df = pd.read_csv(file_path)
    
    # Filter the DataFrame based on the specified column value
    filtered_df = df[df[column_name] == filter_value]
    
    return filtered_df

# Example usage:
if __name__ == '__main__':
    file_path = 'data.csv'  # Path to your CSV file
    column_name = 'status'   # Column to filter by
    filter_value = 'active'   # Value to filter for
    result = filter_csv_by_column_value(file_path, column_name, filter_value)
    print(result)

Views

0

Lines

18

Characters

609

Likes

0

Details

Language
Python
Created
Dec 19, 2025
Updated
29d ago
Size
0.6 KB

Build your snippet library

Join thousands of developers organizing and sharing code snippets.