human
What is a the Python code you requested given the following:
I am working on the file "03_classification.ipynb".
The first task is:
We will also need an imputer for the string categorical columns (the regular Imputer does not work on those):
Can you write Python code for it?
assistant
#Here is the Python code you requested.

# Inspired from stackoverflow.com/questions/25239958
class MostFrequentImputer(BaseEstimator, TransformerMixin):
    def fit(self, X, y=None):
        self.most_frequent = pd.Series([X[c].value_counts().index[0] for c in X],
                                       index=X.columns)
        return self
    def transform(self, X, y=None):
        return X.fillna(self.most_frequent)