title: Why I get more columns than expected after OneHotEncoding in a Sklearn Pipeline?
body: <p>I'm using sklearn pipelines to preprocess my data.</p>
  <pre><code>from sklearn.pipeline import Pipeline
  from sklearn.impute import KNNImputer
  from sklearn.preprocessing import StandardScaler, LabelEncoder, OneHotEncoder
  
  numeric_transformer = Pipeline(steps=[('scaler', StandardScaler()),
      ('imputer', KNNImputer(n_neighbors=2,weights='uniform', metric='nan_euclidean', add_indicator=True))
     ])
  categorical_transformer = Pipeline(steps=[ 
      ('one_hot_encoder', OneHotEncoder(sparse=False, handle_unknown='ignore'))])
  
  
  from sklearn.compose import make_column_selector as selector
  
  numeric_features = ['Latitud','Longitud','Habitaciones','Dormitorios','Baños','Superficie_Total','Superficie_cubierta']
  categorical_features = ['Tipo_de_propiedad']
  from sklearn.compose import ColumnTransformer
  preprocessor = ColumnTransformer(
     transformers=[
      ('numeric', numeric_transformer, numeric_features, selector(dtype_exclude=&quot;category&quot;))
     ,('categorical', categorical_transformer, categorical_features, selector(dtype_include=&quot;category&quot;))])
  </code></pre>
  <p>The feature <code>Tipo_de_propiedad</code> has 3 classes: 'Departamento', 'Casa', 'PH'.  So the 7 other features plus these dummies should give me 10 after transforming, but when I apply <code>fit_transform</code>, it returns 14 features.</p>
  <pre><code>train_transfor=pd.DataFrame(preprocessor.fit_transform(X_train))
  train_transfor.head()
  </code></pre>
  <p><a href="https://i.stack.imgur.com/XNvS4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XNvS4.png" alt="output" /></a></p>
  <p>When I use <code>pd.get_dummies</code> it works well, but I can't use that to apply in the <code>Pipeline</code>; <code>OneHotEncoder</code> is useful because I can fit on train set and transform on the test set.</p>
  <pre><code>dummy=pd.get_dummies(df30[[&quot;Tipo_de_propiedad&quot;]])
  df_new=pd.concat([df30,dummy],axis=1)
  df_new.head()
  </code></pre>
  <p><a href="https://i.stack.imgur.com/BzZbd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BzZbd.png" alt="output" /></a></p>