Skip to content

Commit

Permalink
Merge pull request #9 from fndjjx/master
Browse files Browse the repository at this point in the history
Fix index out of bounds issue when fillna
  • Loading branch information
rhiever authored Jan 18, 2017
2 parents 840c7e5 + 4e29a60 commit 44bcd70
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion datacleaner/datacleaner.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ def autoclean(input_dataframe, drop_nans=False, copy=False, encoder=None,
try:
input_dataframe[column].fillna(input_dataframe[column].median(), inplace=True)
except TypeError:
input_dataframe[column].fillna(input_dataframe[column].mode()[0], inplace=True)
most_frequent = input_dataframe[column].mode()
if len(most_frequent)>0:
input_dataframe[column].fillna(input_dataframe[column].mode()[0], inplace=True)
else:
input_dataframe[column].fillna(method='bfill', inplace=True)
input_dataframe[column].fillna(method='ffill', inplace=True)


# Encode all strings with numerical equivalents
if str(input_dataframe[column].values.dtype) == 'object':
Expand Down

0 comments on commit 44bcd70

Please sign in to comment.