简体   繁体   English

Python中的十分位数

[英]Deciles in Python

I want to group a column into deciles and assign points out of 50.我想将一列分组为十分位数并分配 50 分。

The lowest decile receives 5 points and points are increased in 5 point increments.最低的十分位获得 5 分,分数以 5 分的增量增加。

With below I am able to group my column into deciles.通过下面,我可以将我的列分组为十分位数。 How do I assign points so the lowest decile has 5 points, 2nd lowest has 10 points so on ..and the highest decile has 50 points.我如何分配分数,所以最低的十分位数有 5 分,第二低的有 10 分,依此类推..最高的十分位数有 50 分。

df = pd.DataFrame({'column'[1,2,2,3,4,4,5,6,6,7,7,8,8,9,10,10,10,12,13,14,16,16,16,18,19,20,20,22,24,28]})


df['decile'] = pd.qcut(df['column'], 10, labels = False)```

Simple enough;很简单; you can apply operations between columns directly.您可以直接在列之间应用操作。 Deciles are numbered from 0 through 9, so they are naturally ordered.十分位数从 0 到 9 编号,因此它们是自然排序的。 You want increments of 5 points per decile, so multiplying the deciles by 5 will give you that.您希望每十分位数增加 5 分,因此将十分位数乘以 5 即可。 Since you want to start at 5, you can offset with a simple sum.因为你想从 5 开始,你可以用一个简单的总和来抵消。 The following gives you what I believe you want:以下内容为您提供了我认为您想要的内容:

df['points'] = df['decile'] * 5 + 5

Try this:尝试这个:

df['points'] = df['decile'].add(1).mul(5)

Output:输出:

    column  decile  points
0        1       0       5
1        2       0       5
2        2       0       5
3        3       1      10
4        4       1      10
5        4       1      10
6        5       2      15
7        6       2      15
8        6       2      15
9        7       3      20
10       7       3      20
11       8       3      20
12       8       3      20
13       9       4      25
14      10       4      25
15      10       4      25
16      10       4      25
17      12       5      30
18      13       6      35
19      14       6      35
20      16       6      35
21      16       6      35
22      16       6      35
23      18       7      40
24      19       8      45
25      20       8      45
26      20       8      45
27      22       9      50
28      24       9      50
29      28       9      50

Here's a way that can easily be generalized to different point systems that are not linear with decile:这是一种可以很容易地推广到与十分位数非线性的不同点系统的方法:

df['points'] = df.decile.map({d:5 * (d + 1) for d in range(10)})

This uses Series.map() to map from each decile value to the desired number of points for that decile using a dictionary.这使用Series.map()使用字典从每个十分位值映射到该十分位所需的点数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Python Pandas将客户分类为十分位数? - Categorize Customers into Deciles using Python Pandas? 使用 Python 计算数据集中十分位数的平均成绩,按另一个字段分组 - Calculating mean grades for deciles within a dataset with Python, grouped by another field 如何编写 Python 程序来计算给定数据集的十分位数、百分位数和分位数 - How to write a Python program to calculate the deciles, percentiles, and quantiles for a given data set Python:如何从数字文件(分数)中读取数据以用作列表并获得高分,低分和平均分,并分组为十分位 - Python: How to read from file of numbers (scores) use as list and get high score, low, and average score, and group into deciles 将表数据排序为五分位数/十分位数 - Sorting Table Data into Quintiles/Deciles 根据列的十分位数创建摘要统计信息 - Creating summary stats based on deciles of a column 根据另一列的总和将数据框分类为十分位数的方法 - Way to bin a dataframe into deciles based on sum of another column 如何使用pandas.qcut从列中的值中生成十分位数 - How to use pandas.qcut to make deciles out of values in a column 如何从给定的数据集中确定四分位数和十分位数 - How to determine the quartiles and deciles from a given data set 如何将 dataframe 中的值分配给在另一个 dataframe 中创建的十分位数? - How do I assign values from a dataframe to deciles created in another dataframe?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM