Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4fbc09c

Browse files
cut
1 parent 63330c5 commit 4fbc09c

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@
252252
| 171 | [子类继承父类的静态方法吗?](md/171.md) | staticmethod | V1.0 | ⭐️⭐⭐ |
253253
| 172 | [NumPy 的pad填充方法](md/172.md) | NumPy pad | V1.0 | ⭐️⭐⭐⭐ |
254254
| 173 | [创建下对角线为1、2、3、4的对角矩阵](md/173.md) | NumPy diag | V1.0 | ⭐️⭐⭐ |
255+
| 174 | [cut 数据分箱](md/174.md) | Pandas cut | v1.0 | ⭐️⭐⭐ |
255256

256257
### Python 实战
257258

‎md/174.md‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
11

22
```markdown
33
@author jackzhenguo
4-
@desc
4+
@desc cut 数据分箱
55
@tag
66
@version
7-
@date 2020/03/12
7+
@date 2020/11/28
88
```
9-
9+
10+
第174个小例子:cut 数据分箱
11+
12+
将百分制分数转为A,B,C,D四个等级,bins 被分为 [0,60,75,90,100],labels 等于['D', 'C', 'B', 'A']:
13+
14+
```python
15+
# 生成20个[0,100]的随机整数
16+
In [30]: a = np.random.randint(1,100,20)
17+
In [31]: a
18+
Out[31]:
19+
array([48, 22, 46, 84, 13, 52, 36, 35, 27, 99, 31, 37, 15, 31, 5, 46, 98,99, 60, 43])
20+
21+
# cut分箱
22+
In [33]: pd.cut(a, [0,60,75,90,100], labels = ['D', 'C', 'B', 'A'])
23+
Out[33]:
24+
[D, D, D, B, D, ..., D, A, A, D, D]
25+
Length: 20
26+
Categories (4, object): [D < C < B < A]
27+
```
28+
29+
分箱后,48分对应D,22分对应D,46对应D,84分对应B,...

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /