- 采集到原始的数据中会存在一些噪点数据,噪点数据是对分析无意义或者对分析起到偏执作用的数据。
- 如何清洗:
- 清洗空值/缺失值
- 清洗重复值
- 清洗异常值
import pandas as pd
from pandas import DataFrame,Series
import numpy as np
pandas处理空值操作
- isnull
- notnull
- any
- all
- dropna
- fillna
df = DataFrame(data=np.random.randint(0,100,size=(7,5)))
df.iloc[0,3] = np.nan
df.iloc[3,3] = None
df.iloc[2,2] = np.nan
df.iloc[5,3] = np.nan
df
-
缺失值的处理方案:
- 1.可以将空值对应的行/列进行删除
- 2.可以将空值进行填充
-
将空值对应的行进行删除
ret = df.isnull() #可以通过isnull判断df中是否存在空数据
ret
#监测ret中哪些行存在True(表示df中哪些行存在空值)
ex = ret.any(axis=1) #axis=1表示轴向为行
#any可以对ret表格中的行进行是否存在True的判定,如果存在True,则给该行返回一个True,否则返回False
ex
#整合后的结果;在df中True对应的行是存在空值
ex = df.isnull().any(axis=1)
ex
ex = df.notnull().all(axis=1) #all判断每一行中是否全部为True,如果全部为True,则给该行返回True,否则返回False
ex