0

I'm following this tutorial to select specific rows and columns from a DataFrame.

The tutorial example shows that you can use: adult_names = titanic.loc[titanic["Age"] > 35, "Name"]

to obtain:

1 Cumings, Mrs. John Bradley (Florence Briggs Th...

6 McCarthy, Mr. Timothy J

11 Bonnell, Miss. Elizabeth

13 Andersson, Mr. Anders Johan

15 Hewlett, Mrs. (Mary D Kingcome)

Name: Name, dtype: object

However, if I want to access Miss. Elizabeth Bonnell, I'd have to use adult_names[11] (even though she's the 3rd name older than 35).

Is there a way to populate an array with these values so that the first name would be in adult_names[0], the second name would be in adult_names[1], the third name would be in adult_names[2], etc.?

d52
  • 1
  • 1
  • USe `adult_names = titanic.loc[titanic["Age"] > 35, "Name"].tolist()` or `adult_names = titanic.loc[titanic["Age"] > 35, "Name"].to_numpy()` – jezrael Apr 29 '22 at 08:48

2 Answers2

0

do you want something like this ?

adult_names = list(titanic.loc[titanic["Age"] > 35, "Name"].values)
DataSciRookie
  • 798
  • 1
  • 3
  • 12
0

you could also just use adults_name and use the iloc. adult_name[11] is the same as adult_name.iloc[2]. iloc is indexing by position.

Rabinzel
  • 7,757
  • 3
  • 10
  • 30