I saw a bunch of questions have this error but I could not understand the relation with my code or problem.
I am trying to fix the NaN values in the data which I got from a sample CSV file that I found on the internet. My code is very simple actually:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Importing stuff.
from sklearn.preprocessing import Imputer
import pandas
# Loading the corrupt data
corrupt_data = pandas.read_csv('SampleCorruptData.csv')
#Creating Imputer object
imputer = Imputer(missing_values = 'NaN', strategy= "mean", axis = 0)
owner_id = corrupt_data.iloc[:,2:]
print(owner_id)
imputer = imputer.fit(owner_id.iloc[:,2:])
owner_id.iloc[:,2:] = imputer.transform(owner_id[:,2:])
print(owner_id)
The CSV file:
GroupName,Groupcode,GroupOwner
System Administrators,sysadmin,13456
Independence High Teachers,HS Teachers,
John Glenn Middle Teachers,MS Teachers,13458
Liberty Elementary Teachers,Elem Teachers,13559
1st Grade Teachers,1stgrade,NaN
2nd Grade Teachers,2nsgrade,13561
3rd Grade Teachers,3rdgrade,13562
Guidance Department,guidance,NaN
Independence Math Teachers,HS Math,13660
Independence English Teachers,HS English,13661
John Glenn 8th Grade Teachers,8thgrade,
John Glenn 7th Grade Teachers,7thgrade,13452
Elementary Parents,Elem Parents,NaN
Middle School Parents,MS Parents,18001
High School Parents,HS Parents,18002
As you can see the NaN values.
The Error I get:
Traceback (most recent call last):
File "<ipython-input-21-1bfc8eb216cc>", line 1, in <module>
runfile('/home/teoman/Desktop/data science/Fix Corrupt Data/imputation.py', wdir='/home/teoman/Desktop/data science/Fix Corrupt Data')
File "/usr/lib/python3/dist-packages/spyder/utils/site/sitecustomize.py", line 866, in runfile
execfile(filename, namespace)
File "/usr/lib/python3/dist-packages/spyder/utils/site/sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "/home/teoman/Desktop/data science/Fix Corrupt Data/imputation.py", line 18, in <module>
imputer = imputer.fit(owner_id.iloc[:,2:])
File "/home/teoman/.local/lib/python3.5/site-packages/sklearn/preprocessing/imputation.py", line 155, in fit
force_all_finite=False)
File "/home/teoman/.local/lib/python3.5/site-packages/sklearn/utils/validation.py", line 470, in check_array
context))
ValueError: Found array with 0 feature(s) (shape=(15, 0)) while a minimum of 1 is required.
What do I do wrong here?