Write a Pandas program to find the positions of the values neighboured by smaller values on both sides in a given series
- برمجة بايثون
- 2021-09-10
- mhanasmh00489829403
الأجوبة
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]
أسئلة مشابهة
القوائم الدراسية التي ينتمي لها السؤال