0

I want to calculate mssing value by mean method from the dataset but it gives me

error unhashable type: 'slice'


CODE:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
dataset= pd.read_csv('Data.csv')
m=dataset.iloc[:,:-1].values
X= pd.DataFrame(m)
n=dataset.iloc[:,-1].values
Y= pd.DataFrame(n)

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])
Cœur
  • 37,241
  • 25
  • 195
  • 267
ABHAY KOTAL
  • 153
  • 3
  • 13

1 Answers1

0

You can't Slice a DataFrame like below

 `'X[:,1:3]'`.

You should slice using 'iloc' or another way round it would be using 'values'

  'X.iloc[:,1:3]'

  'X.values[:,1:3]'
Fasty
  • 784
  • 1
  • 11
  • 34