When applying conditions based on value_counts() to an dataframe, a "boolean dataframe" is obtained, as in the example below:
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.
IIUC transform
与nunique
targetdf=sal[sal[sal["Year"] == 2013].groupby(["JobTitle"]).transform('nunique')==1].copy()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.