File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 253253| 172 | [ NumPy 的pad填充方法] ( md/172.md ) | NumPy pad | V1.0 | ⭐️⭐⭐⭐ |
254254| 173 | [ 创建下对角线为1、2、3、4的对角矩阵] ( md/173.md ) | NumPy diag | V1.0 | ⭐️⭐⭐ |
255255| 174 | [ cut 数据分箱] ( md/174.md ) | Pandas cut | v1.0 | ⭐️⭐⭐ |
256+ | | [ 丢弃空值和填充空值] ( ./md/175.md ) | Pandas dropna fillna | v1.0 | ⭐️⭐⭐ |
256257
257258### Python 实战
258259
Original file line number Diff line number Diff line change 11
22``` markdown
33@author jackzhenguo
4- @desc
4+ @desc 丢弃空值和填充空值
55@tag
66@version
77@date 2020/03/13
88```
9-
9+
10+ 丢弃空值
11+
12+ np.nan 是 pandas 中常见空值,使用 dropna 过滤空值,axis 0 表示按照行,1 表示按列,how 默认为 any ,意思是只要有一个 nan 就过滤某行或某列,all 所有都为 nan
13+
14+ ``` python
15+ # axis 0 表示按照行,all 此行所有值都为 nan
16+ df.dropna(axis = 0 , how = ' all' )
17+ ```
18+
19+ 充填空值
20+
21+ 空值一般使用某个统计值填充,如平均数、众数、中位数等,使用函数 fillna:
22+
23+ ``` python
24+ # 使用a列平均数填充列的空值,inplace true表示就地填充
25+ df[" a" ].fillna(df[" a" ].mean(), inplace = True )
26+ ```
27+
You can’t perform that action at this time.
0 commit comments