Pandas

Pandas (52)

Jun's N 2022. 9. 21. 01:05

How to find the position of the nth largest value greater than a given value?

# Input
ser = pd.Series(np.random.randint(1, 100, 15))

# Solution
print('ser: ', ser.tolist(), 'mean: ', round(ser.mean()))
np.argwhere(ser > ser.mean())[1]

# output 1
ser:  [7, 77, 16, 86, 60, 38, 34, 36, 83, 27, 16, 52, 50, 52, 54] mean:  46
# output 2
array([3])
728x90