Skip to content

Instantly share code, notes, and snippets.

@doron2402
Last active October 17, 2017 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doron2402/9e92cd07380da09ec6d65aee549922c2 to your computer and use it in GitHub Desktop.
Save doron2402/9e92cd07380da09ec6d65aee549922c2 to your computer and use it in GitHub Desktop.
filling missing value python
import pandas as pd
import sklearn as sk
# import the dataset
dataset = pd.read_csv(‘db.csv’)
# Load all columns into matrix but not the last ones
x = dataset.iloc[0:12,0:5].values
# Last column from the dataset
y = dataset.iloc[0:12,6].values
# Use the mean for fill missing data
imputer = sk.preprocessing.Imputer()
imputer = imputer.fit(x[0:12,3:5])
x[0:12,3:5] = imputer.transform(x[0:12,3:5])
# now the missing value will be filled with the mean of the column
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment