[Python] How to filter rows in a Pandas DataFrame based on multiple conditions?

Discussão em 'Python' iniciado por Stack, Abril 24, 2025.

  1. Stack

    Stack Membro Participativo

    Im working on a data analysis project using Python and Pandas. I have a DataFrame that looks like this: import pandas as pd

    data = {
    'Name': ['Ali', 'Sara', 'John', 'Aisha'],
    'Age': [25, 30, 22, 28],
    'City': ['Riyadh', 'Jeddah', 'Riyadh', 'Dammam']
    }

    df = pd.DataFrame(data)


    I want to filter the DataFrame to get only the rows where the city is “Riyadh” and the age is greater than 23.

    I tried this:

    But I got an error:

    ValueError: The truth value of a Series is ambiguous


    How can I apply multiple conditions correctly to filter this DataFrame?

    Continue reading...

Compartilhe esta Página