Home > front end >  Is there any way to find the missing values in given dataset
Is there any way to find the missing values in given dataset

Time:05-28

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:

Dataset

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.

CodePudding user response:

You need change X[:,1:3] to X.iloc[:,1:3]

  • Related