我正在尝试基于particluar DataFrame列值创建用户组。我想基于total_usage
度量为整个数据帧的总体创建10个用户组。数据帧df
的示例如下所示。你知道吗
user_id total_usage
1 10
2 10
3 20
4 20
5 30
6 30
7 40
8 40
9 50
10 50
11 60
12 60
13 70
14 70
15 80
16 80
17 90
18 90
19 100
20 100
df
只是超过6000条记录的整个数据帧的一个片段,但是我只希望有10个用户组。你知道吗
下面是我想要的输出的一个例子。你知道吗
user_id total_usage user_group
1 10 10th_group
2 10 10th_group
3 20 9th_group
4 20 9th_group
5 30 8th_group
6 30 8th_group
7 40 7th_group
8 40 7th_group
9 50 6th_group
10 50 6th_group
11 60 5th_group
12 60 5th_group
13 70 4th_group
14 70 4th_group
15 80 3th_group
16 80 3th_group
17 90 2nd_group
18 90 2nd_group
19 100 1st_group
20 100 1st_group
任何人能提供的任何帮助都将不胜感激。你知道吗
用^{} 改变负片的顺序,用^{} 表示
1.st
和2.nd
值:尝试将
pd.Series
与np.repeat
、np.arange
、pd.DataFrame.groupby
、pd.Series.astype
、pd.Series.map
和pd.Series.fillna
一起使用:现在:
是:
看起来您正在查找
qcut
,但顺序相反输出,它不是序数,但我希望它能:
相关问题 更多 >
编程相关推荐