{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "[![Open in Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/justmarkham/scikit-learn-tips/master?filepath=notebooks%2F42_passthrough_or_drop.ipynb)\n", "\n", "[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/justmarkham/scikit-learn-tips/blob/master/notebooks/42_passthrough_or_drop.ipynb)\n", "\n", "# 🤖⚡ scikit-learn tip #42 ([video](https://www.youtube.com/watch?v=vHGRXuOtFnE&list=PL5-da3qGB5ID7YYAqireYEew2mWVvgmj6&index=42))\n", "\n", "In a ColumnTransformer, you can use the strings 'passthrough' and 'drop' in place of a transformer. Useful if you need to passthrough some columns and drop others!\n", "\n", "See example 👇" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np\n", "from sklearn.impute import SimpleImputer\n", "from sklearn.compose import make_column_transformer" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "impute = SimpleImputer()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "X = pd.DataFrame({'A':[1, 2, np.nan],\n", " 'B':[10, 20, 30],\n", " 'C':[100, 200, 300],\n", " 'D':[1000, 2000, 3000],\n", " 'E':[10000, 20000, 30000]})" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/html": [ "
\n", " | A | \n", "B | \n", "C | \n", "D | \n", "E | \n", "
---|---|---|---|---|---|
0 | \n", "1.0 | \n", "10 | \n", "100 | \n", "1000 | \n", "10000 | \n", "
1 | \n", "2.0 | \n", "20 | \n", "200 | \n", "2000 | \n", "20000 | \n", "
2 | \n", "NaN | \n", "30 | \n", "300 | \n", "3000 | \n", "30000 | \n", "