多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
~~~ #!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2019/1/1 0001 下午 02:37 # @Author : 黄药师 # @desc : 处理丢失数据 # @File : pandasLose.py # @Software: PyCharm import pandas as pd import numpy as np dates = np.arange(20170101, 20170105) df1 = pd.DataFrame(np.arange(12).reshape(4, 3), index=dates, columns=['A', 'B', 'C']) print(df1) df2 = pd.DataFrame(df1, index=dates, columns=['A', 'B', 'C', 'D', 'E']) print(df2) s1 = pd.Series([3, 4, 6], index=dates[:3]) print(s1) s2 = pd.Series([32, 5, 6], index=dates[1:]) print(s2) df2['D'] = s1 df2['E'] = s2 print(df2) # 剔除有空值的行和列 df3 = df2.dropna(axis=0, how='any') # axis=[0,1] 0代表行,1代表列. how=['any','all'] any:任意一个,all:全部 print(df3) df4 = df2.dropna(axis=1, how='any') print(df4) # 给空值赋值 df5 = df2.fillna(value=0) print(df5) # 查看空值 print(df2.isnull()) # 判断表里是否有空值.只要有一个或多个空值,都会返回true np1 = np.any(df2.isnull()) print(np1) # 所有值为空值时才返回true np2 = np.all(df2.isnull()) print(np2) ~~~