我的日期框架结构如下:
df = pd.DataFrame({'GROUP_ID': np.random.randint(1, 7, size=100),
'VALUES': np.random.randint(0, 50, size=100)})
df['THRESHOLD'] = df['GROUP_ID']*5
df = df[['GROUP_ID','VALUES','THRESHOLD']]
df.sort_values(by='GROUP_ID', inplace=True)
(这只是一个例子)
列阈值实际上是每个组的百分位数(单位%)。 我需要添加一个“百分位数”列,其中每个组中的值应该有一个百分位数的数值
我试图使用groupby
和apply
,但我不知道如何将THRESHOLD列的值传递给quantile\percentile
函数中的参数q
为传递给函数^{} 的} 的新列,仅需要介于0和1之间的treshold:
GROUP_ID
创建字典并映射具有x.name
的treshold,对于具有^{相关问题 更多 >
编程相关推荐