I need to get the first and last names of people who work in HR department.
FirstName LastName Year Department 83 Joe Faulk 2 Austin Public Library 84 Bryce Benton 5 HR 85 Sarah Cronin 7 Austin Public Library 86 Gabriel Montgomery 2 Austin Resource Recovery 87 Patricia Genty-Andrade 3 HR
This is my code it shows me error AttributeError: 'DataFrame' object has no attribute 'unique'
names = df.iloc[:, 0:4][df['Department'] == 'HR'].unique()
I need the output to be like this
FirstName LastName Department 0 Joe Faulk HR 1 Bryce Benton HR 2 Sarah Cronin HR 3 Gabriel Montgomery HR 4 Patricia Genty-Andrade HR
use drop_duplicates instead of unique, as unique is for Series.
drop_duplicates
unique
df.loc[df['Department'] == 'HR', ['FirstName', 'LastName', 'Department']].drop_duplicates()
2.1m questions
2.1m answers
60 comments
57.0k users