網(wǎng)站首頁(yè) 編程語(yǔ)言 正文
一、構(gòu)建示例數(shù)據(jù)
import pandas as pd
import numpy as np
data = {"ID":[202001, 202002, 202003, 202004, 202005, 202006, 202007, 202008, 202009, 202010],
"Chinese":[98, 67, 84, 88, 78, 90, 93, np.nan, 82, 87],
"Math":[92, 80, 73, np.nan, 88, 78, 90, 82, 77, 69],
"English":[88, 79, 90, 73, 79, 83, 81, np.nan, 71, np.nan]
}
df = pd.DataFrame(data)
df
二、檢查缺失值的n種方法
2.1 確認(rèn)是否有缺失值的兩種方法
df.isnull().values.any()
True
df.isnull().sum().any()
True
2.2 查看缺失數(shù)目和缺失率
df.isnull().sum()
all_data_na = (df.isnull().sum()/len(df))*100
all_data_na = all_data_na.drop(all_data_na[all_data_na == 0].index).sort_values(ascending=False)
missing_data = pd.DataFrame({'缺失率' : all_data_na})
missing_data
2.3 查看非缺失值數(shù)目
df.info()
df.shape[0] - df.isnull().sum()
df.notnull().sum()
三、缺失值填充三種示例
# 用上下平均值填充English
df['English'] = df['English'].fillna(df['English'].interpolate())
df.head(10)
# 用中位數(shù)填充value列:
df['Math'] = df['Math'].fillna(df['Math'].median())
df.head(10)
# 用-1填充Chinese列:
df['Chinese'] = df['Chinese'].fillna(-1)
df.head(10)
原文鏈接:https://blog.csdn.net/zzpl139/article/details/128613459
相關(guān)推薦
- 2022-08-15 Spring框架??贾R(shí)點(diǎn)總結(jié)
- 2022-12-10 Qt中簡(jiǎn)單的按鈕槽函數(shù)傳遞參數(shù)方法_C 語(yǔ)言
- 2022-09-21 Redis緩存更新策略詳解_Redis
- 2022-09-17 C++中cin>>n的返回值_C 語(yǔ)言
- 2023-10-11 Mybatis-Plus條件構(gòu)造器的select
- 2022-08-23 使用Python腳本提取基因組指定位置序列_python
- 2022-10-09 React路由封裝的實(shí)現(xiàn)淺析_React
- 2023-02-18 go?micro微服務(wù)框架項(xiàng)目搭建方法_Golang
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過(guò)濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支