Extract Items from a Series at Given Positions

Each element in a series has an index that identifies its location within the series. This thread will explain various techniques for extracting values using simple code examples to help you understand the methods more effectively.

1. Using "iloc" indexer:

  • The iloc indexer is a positional indexer that selects data based on its position in the series.
  • In the example below, we extract the items at positions 0, 2 and 4 from a series.

2. Using boolean indexing:

  • In this technique, you create a list of Boolean values, where each value represents the position of an item in the series.
  • By passing this list, the values at the indexes where the Boolean values are True are extracted. This is a straightforward method.

3. Using "take()" method:

  • The take() method takes a list of indices and returns a new series with the values at those indices.
  • In the example below, we extract the items at positions 0, 2 and 4 from a series.