0

Say I have below data frame named df where the column names are Name and Age:

enter image description here

and I have a list [Jack, Sarah]. I want to get [28, 21] (the order of the names is important). How can I do this most effectively?

user5054
  • 1,056
  • 1
  • 7
  • 22
  • 1
    `df.loc[df.Name.isin(['Jack', 'Sarah']), 'Age'].tolist()` – user3483203 Jun 24 '19 at 22:04
  • Looks like this does not keep the order of the input list (i.e., if the input list is `['Sarah', 'Jack']`, then I would get `[21, 28]` not `[28,21]`), which is something that I need (see my question) and here is my solution keeping the order: `df.index = df.Name` followed by `df.Age[input_list]` – user5054 Jun 27 '19 at 16:44

0 Answers0