dropna fillna

# NaN 浮点类型   np.nan+1 =>nan

Python type(None)  // NoneType类型 不能参与运算

import pandas as pd
from pandas import Series,DataFrame

#数据提取
df = pd.read_excel('./测试数据.xlsx')
df.head()
如何检测空值?
df.isnull().any(axis=1 行
) True行存在空值 false行不存在空 df.notnull().all(axis=1) True行无空 false行有空
df.isnull().any(axis=0) #检测哪些列中存在空值
#剔除无用的列
df.drop(labels=['none','none1'],axis=1,inplace=True) #列/行 反向

df.isnull().any(axis=1)  #拿到空值  行
indexs = ~(df.isnull().any(axis=1)) #取反
df.loc[indexs] #获取false的行 就是正常结果
len(df.loc[indexs]) #求长度

#封装的函数 删除行
df.dropna(0,
"any") #drop系列0是行 参数(axis,how)
# 填充 back 下/右 forward 上/左 n_df = df.fillna(method='bfill',axis=0).fillna(method='ffill',axis=0) #0
n_df.isnull().any(axis=0) #检测哪些列中存在空值
posted @ 2019-05-14 20:38  追风zz  阅读(332)  评论(0编辑  收藏  举报