Skip to main content

df.take()

df.take(indices)

Return the elements in the given positional indices.

Input:
indices : array
An array of ints indicating which positions to take.
Returns:
A DataFrame with only the indices specified.
Return Type:
DataFrame

pets
IndexIDSpeciesColorWeightAgeIs_CatOwner_Comment
0dog_001dogblack405False There are no bad dogs, only bad owners.
1cat_001catgolden1.50.2TrueMy best birthday present ever!!!
2cat_002catblack159True****All you need is love and a cat.****
3dog_002dogwhite802FalseLove is a wet nose and a wagging tail.
4dog_003dogblack250.5FalseBe the person your dog thinks you are.
5ham_001hamsterblack13FalseNo, thank you!
6ham_002hamstergolden0.250.2FalseNo, thank you!
7cat_003catblack100TrueNo, thank you!
# take the top 5 rows of the DataFrame. (indices 0, 1, 2, 3, 4)
pets.take(np.arange(5))
IndexIDSpeciesColorWeightAgeIs_CatOwner_Comment
0dog_001dogblack405False There are no bad dogs, only bad owners.
1cat_001catgolden1.50.2TrueMy best birthday present ever!!!
2cat_002catblack159True****All you need is love and a cat.****
3dog_002dogwhite802FalseLove is a wet nose and a wagging tail.
4dog_003dogblack250.5FalseBe the person your dog thinks you are.
# 0, 2, 4 indices.
pets.take(np.arange(0, 6, 2))
IndexIDSpeciesColorWeightAgeIs_CatOwner_Comment
0dog_001dogblack405False There are no bad dogs, only bad owners.
2cat_002catblack159True****All you need is love and a cat.****
4dog_003dogblack250.5FalseBe the person your dog thinks you are.