zoukankan      html  css  js  c++  java
  • 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) #检测哪些列中存在空值
  • 相关阅读:
    Today
    react-decorator-track 解耦-埋点方案
    Decorator
    webpack4强势来袭
    同源策略与跨域处理
    html语义化
    深度遍历与广度遍历的理解
    Javascript 模块化理解
    算法之排序
    数组去重
  • 原文地址:https://www.cnblogs.com/zhangchen-sx/p/10864443.html
Copyright © 2011-2022 走看看