﻿ Pandas Data Series: Extract items at given positions of a given series - w3resource # Pandas Data Series: Extract items at given positions of a given series

## Pandas: Data Series Exercise-22 with Solution

Write a Pandas program to extract items at given positions of a given series.

Sample Solution :

Python Code :

``````import pandas as pd
num_series = pd.Series(list('2390238923902390239023'))
element_pos = [0, 2, 6, 11, 21]
print("Original Series:")
print(num_series)
result = num_series.take(element_pos)
print("\nExtract items at given positions of the said series:")
print(result)
``````

Sample Output:

```Original Series:
0     2
1     3
2     9
3     0
4     2
5     3
6     8
7     9
8     2
9     3
10    9
11    0
12    2
13    3
14    9
15    0
16    2
17    3
18    9
19    0
20    2
21    3
dtype: object

Extract items at given positions of the said series:
0     2
2     9
6     8
11    0
21    3
dtype: object
```

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz

﻿

## Python: Tips of the Day

Returns a list with n elements removed from the beginning

Example:

```def tips_take(itr, n = 1):
return itr[:n]
print(tips_take([1, 2, 3], 5))
print(tips_take([1, 2, 3], 0))
```

Output:

```[1, 2, 3]
[]
```