Python 数据清洗--处理Nan
Posted ann21
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python 数据清洗--处理Nan相关的知识,希望对你有一定的参考价值。
参考:http://blog.sina.com.cn/s/blog_13050351e0102xfis.html
https://www.sogou.com/link?url=DOb0bgH2eKh1ibpaMGjuy-bS_O7xQYLPIOogrOFmc02ueKW9M67CaVLpMY1k7wxTCB1NmnNSzM-t5pUc3zy0dg..
https://www.sogou.com/link?url=DOb0bgH2eKh1ibpaMGjuy6YnbQPc3cuKWH5w_8iuvJBomuBEhdSpHkUUZED5fr2OXwl-dB-nkEs_c1NbUyGLxQ..
https://jingyan.baidu.com/article/ca00d56c1b3647e99eebcfbd.html
`import numpy as np
import pandas as pd
from pandas import Series,DataFrame
from numpy import nan as NaN
import tensorflow as tf
import matplotlib.pyplot as plt
import scipy.io as sio
import os
from sklearn import preprocessing
读取mat数据
load_path="08_1.mat"
load_data = sio.loadmat(load_path)
a = load_data[‘D‘]
print(a)
data = DataFrame(a)
print(data)
data.fillna(0)
print(data.fillna(0))
b=data.fillna(0).values
print(b)
数据归一化
a2 = preprocessing.scale(b)
print(‘数据归一化:‘)
print(a2)
数据清洗方法2 删除NAN所在的列
load_path2="08_1.mat"
load_data2 = sio.loadmat(load_path2)
a2 = load_data2[‘D‘]
print(a2)
data2 = DataFrame(a2)
data2.dropna(axis=0, how=‘any‘)
print(data2.dropna(axis=0, how=‘any‘))`
处理前:
处理后:
以上是关于Python 数据清洗--处理Nan的主要内容,如果未能解决你的问题,请参考以下文章