[Python] Using conditions in pandas value_counts()

Discussão em 'Python' iniciado por Stack, Setembro 5, 2025.

  1. Stack

    Stack Membro Participativo

    When applying conditions based on value_counts() to an dataframe, a "boolean dataframe" is obtained, as in the example below:

    • The csv I am using for the example is this one.

    import pandas as pd
    sal = pd.read_csv("Salaries.csv")
    sal[sal["Year"] == 2013]["JobTitle"].value_counts() == 1


    Instead of obtaining these booleans, is it possible to filter the dataframe in order to display the actual data of the rows that returned True to the condition?

    In the example, the filtered dataframe would have the information (EmployeeName, BasePay, Id...) about each employee that have an unique JobTitle.

    Continue reading...

Compartilhe esta Página