1

I have a dataframe from which I want to create a list of names that fit a certain characteristics. For example, this is the dataframe:

name    age     hair color
Tim     32  black
Alex    29  red
Jerry   25  brown
Molly   30  black
Susan   27  black

How could I make a list of only the names that have black hair?

pdfranco
  • 31
  • 1
  • `df.loc[df['hair color'].eq('black'),'name'].tolist()` – anky May 21 '20 at 15:14
  • 1
    `df.name[df['hair color']=='black']` – Ch3steR May 21 '20 at 15:14
  • Does this answer your question? [Filtering Pandas column with specific conditions?](https://stackoverflow.com/questions/53311599/filtering-pandas-column-with-specific-conditions) – dsanatomy May 21 '20 at 15:43
  • Does this answer your question? [How to select rows from a DataFrame based on column values?](https://stackoverflow.com/questions/17071871/how-to-select-rows-from-a-dataframe-based-on-column-values) – ggorlen May 21 '20 at 15:47

1 Answers1

0

Try:

df[df['hair color']=='black']['name'].tolist()
Kriti Pawar
  • 832
  • 7
  • 15