简体   繁体   English

Python中的数据预处理

[英]Data preprocessing in Python

Heyy, I am new to data science and here I am trying to find missing data in one of the columns.But, I am encountering an error which states that "X is not defined".嘿,我是数据科学的新手,在这里我试图在其中一列中查找丢失的数据。但是,我遇到了一个错误,指出“X 未定义”。 Can someone help me?有人可以帮助我吗?

#missing data
from sklearn.preprocessing import Imputer
imputer = Imputer(missing_values='NaN', strategy ='mean', axis =0)
imputer = imputer.fit(X[:, 1:3])
X[:, 1:3] = imputer.transform(X[:, 1:3])

The "X" denotes an numpy.ndarray of your primary DataFrame, minus the target variable. “X”表示主 DataFrame 的 numpy.ndarray,减去目标变量。

X = df.iloc[:, :-1].values

Try this.试试这个。 Should be working.应该工作。

To find the missing data for a single column, the below code is must worked.要查找单个列的缺失数据,必须使用以下代码。

dataset_name['column_name'].isnull().sum() dataset_name['column_name'].isnull().sum()

Note: if we need to find the missing data then not bother about X variable.注意:如果我们需要找到缺失的数据,那么就不必担心 X 变量。 X and y variables are needed when you try to fill the missing data with some mean/median/mode values.当您尝试用一些均值/中值/众数值填充缺失数据时,需要 X 和 y 变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM