I have a simple quantile function that I was going to use to select some data. I am trying to convert that function to a lambda function, but it does not appear to be working the way I expected. I want the lambda function to be able to set values above the 90th percentile as 'yes' and those below as 'no'. Need help figuring out what I am doing wrong.
Below is the code with a small set of data for illustrative purposes.
import pandas as pd
import numpy as np
# the simple function
def selector(x):
return np.quantile(x, 0.90)
# the lambda function (not working properly.)
df.apply(lambda x: 'yes' if (x >= np.quantile(x, 0.90)) else 'no'))
df = pd.DataFrame({'tm': [263, 257, 263, 268, 268,259, 265,
263, 256, 263, 264, 268, 268, 263,
262, 260, 262, 235, 263, 264, 264]})