w3resource

Python Pandas: Find the positions of numbers that are multiples of 5 of a given series

Python Pandas: Data Series Exercise-21 with Solution

Write a Pandas program to find the positions of numbers that are multiples of 5 of a given series.

Sample Solution :

Python Code :

import pandas as pd
import numpy as np
num_series = pd.Series(np.random.randint(1, 10, 9))
print("Original Series:")
print(num_series)
result = np.argwhere(num_series % 5==0)
print("Positions of numbers that are multiples of 5:")
print(result)

Sample Output:

Original Series:
0    1
1    9
2    8
3    6
4    9
5    7
6    1
7    1
8    1
dtype: int64
Positions of numbers that are multiples of 5:
[]        

Python Code Editor:


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

Previous: Write a Pandas program to find the positions of numbers that are multiples of 5 of a given series.
Next: Write a Pandas program to extract items at given positions of a given series.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz



Python: Tips of the Day

Python: Membership Testing in a Collection

>>> a = ('one', 'two', 'three', 'four', 'five')
>>> if 'one' in a:
...     print('The tuple contains one.')
... 
The tuple contains one.
>>> b = {0: 'zero', 1: 'one', 2: 'two', 3: 'three'}
>>> if 2 in b.keys():
...     print('The dict has the key of 2.')
... 
The dict has the key of 2.