Write a Pandas program to find the positions of the values neighboured by smaller values on both sides in a given series
import pandas as pd import numpy as np nums = pd.Series([1, 8, 7, 5, 6, 5, 3, 4, 7, 1]) print("Original series:") print(nums) print("\nPositions of the values surrounded by smaller values on both sides:") temp = np.diff(np.sign(np.diff(nums))) result = np.where(temp == -2)[0] + 1 print(result)
Sample Output:
Original series: 0 1 1 8 2 7 3 5 4 6 5 5 6 3 7 4 8 7 9 1 dtype: int64 Positions of the values surrounded by smaller values on both sides: [1 4 8]
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer