[英]Is there any way to find the missing values in given dataset
the code is as follows代码如下
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
Dataset = pd.read_csv('/Users\HANISH\Desktop\mllearning\Datapreprocessing\Data.csv')
X = Dataset.iloc[:,:-1]
Y = Dataset.iloc[:,-1]
from sklearn.impute import SimpleImputer
imputer = SimpleImputer(missing_values=np.nan, strategy='mean')
imputer.fit(X[:,1:3])
X[:,1:3] = imputer.transform(X[:,1:3])
print(X)
Data I am using is:我使用的数据是:
The error I am getting is as follows:我收到的错误如下:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File ~\.spyder-py3\temp1.py:18 in <module>
imputer.fit(X[:,1:3])
File C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\frame.py:3505 in __getitem__
indexer = self.columns.get_loc(key)
File C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\indexes\base.py:3628 in get_loc
self._check_indexing_error(key)
File C:\ProgramData\Anaconda3\lib\site-packages\pandas\core\indexes\base.py:5637 in _check_indexing_error
raise InvalidIndexError(key)
InvalidIndexError: (slice(None, None, None), slice(1, 3, None))
Please suggest me the changes as I started just learning.请在我刚开始学习时建议我进行更改。
You need change X[:,1:3]
to X.iloc[:,1:3]
您需要将X[:,1:3]
更改为X.iloc[:,1:3]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.