{"id":8646,"library":"sklearn-pandas","title":"sklearn-pandas","description":"sklearn-pandas (current version 2.2.0) provides a bridge between Scikit-Learn's machine learning methods and pandas DataFrames. It allows users to map DataFrame columns to different scikit-learn transformations, which are then recombined into features for model training. The library aims to streamline data preprocessing workflows involving both pandas and scikit-learn.","status":"active","version":"2.2.0","language":"python","source_language":"en","source_url":"https://github.com/scikit-learn-contrib/sklearn-pandas","tags":["data transformation","scikit-learn","pandas","machine learning","feature engineering","preprocessing"],"install":[{"cmd":"pip install sklearn-pandas","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Fundamental numerical computing library for array operations.","package":"numpy","optional":false},{"reason":"Core data structure for DataFrames used in mapping transformations.","package":"pandas","optional":false},{"reason":"Scientific computing library, often a dependency of scikit-learn.","package":"scipy","optional":false},{"reason":"Machine learning library providing the transformers and estimators.","package":"scikit-learn","optional":false}],"imports":[{"wrong":"from sklearn_pandas import DataFrameMapper","symbol":"DataFrameMapper","correct":"from sklearn_pandas import DataFrameMapper"},{"symbol":"CategoricalImputer","correct":"from sklearn_pandas import CategoricalImputer"},{"symbol":"cross_val_score","correct":"from sklearn_pandas import cross_val_score"}],"quickstart":{"code":"import pandas as pd\nfrom sklearn_pandas import DataFrameMapper\nfrom sklearn.preprocessing import LabelBinarizer, StandardScaler\n\ndata = pd.DataFrame({\n    'pet': ['cat', 'dog', 'dog', 'fish', 'cat', 'dog', 'cat', 'fish'],\n    'children': [4., 6, 3, 3, 2, 3, 5, 4],\n    'salary': [90., 24, 44, 27, 32, 59, 36, 27]\n})\n\n# Map DataFrame columns to Scikit-learn transformations\nmapper = DataFrameMapper([\n    ('pet', LabelBinarizer()),\n    (['children'], StandardScaler()),\n    ('salary', None) # 'None' keeps the column without transformation\n], df_out=True) # Set df_out=True to get a DataFrame output (requires pandas >= 1.0)\n\ntransformed_data = mapper.fit_transform(data.copy())\nprint(transformed_data.head())\nprint(transformed_data.columns)","lang":"python","description":"This quickstart demonstrates how to use `DataFrameMapper` to apply different scikit-learn transformers to specific columns of a pandas DataFrame. Categorical 'pet' column is binarized, 'children' is standardized, and 'salary' is kept as is. Setting `df_out=True` (requires pandas >= 1.0) ensures the output is a DataFrame rather than a NumPy array."},"warnings":[{"fix":"Avoid using `NumericalTransformer`. For common numerical transformations, use `sklearn.preprocessing` modules or custom `FunctionTransformer` instances.","message":"`NumericalTransformer` was deprecated in `v2.1.0` and is slated for removal in a future release. Users should migrate to native scikit-learn transformers or implement custom transformers.","severity":"deprecated","affected_versions":">=2.1.0"},{"fix":"Replace `CategoricalImputer` with `sklearn.impute.SimpleImputer(strategy='most_frequent')`. For cross-validation and grid search, use `sklearn.model_selection.cross_val_score` and `GridSearchCV` directly, as they now support pandas DataFrames.","message":"Functionalities like `CategoricalImputer`, `cross_val_score`, and `GridSearchCV` were removed in `sklearn-pandas v2.0.0`. Their equivalent features are now available directly within `scikit-learn`.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"To receive a pandas DataFrame as output (if using pandas >= 1.0), initialize `DataFrameMapper` with `df_out=True`. Otherwise, manually convert the output NumPy array back to a DataFrame and re-add column names if needed.","message":"By default, `DataFrameMapper.transform()` outputs a NumPy array, not a pandas DataFrame. This can lead to loss of column names and type information.","severity":"gotcha","affected_versions":"<2.2.0 (and default in >=2.2.0)"},{"fix":"For transformers expecting 2D input (e.g., `StandardScaler`), always pass column names as a list: `(['column_name'], Transformer())`. For transformers that can handle 1D input (e.g., `LabelBinarizer`), a string is often sufficient, but using a list ensures 2D input.","message":"The way a column is specified in `DataFrameMapper` (e.g., `'column_name'` vs. `['column_name']`) affects the shape of the array passed to the transformer (1D array vs. 2D array/column vector). Some scikit-learn transformers expect a 2D input.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consider `scikit-learn`'s native DataFrame output features and `ColumnTransformer` alongside `sklearn-pandas` for new projects or when refactoring, especially if a simpler pipeline without complex column selection logic is sufficient.","message":"While `sklearn-pandas` bridges DataFrame functionality, recent versions of `scikit-learn` (v1.2+) introduced native `set_config(transform_output=\"pandas\")` for transformers. This may reduce the need for `sklearn-pandas` in certain `sklearn.pipeline` contexts, but `DataFrameMapper` still offers granular column-wise transformation definition.","severity":"gotcha","affected_versions":"scikit-learn >= 1.2"}],"env_vars":null,"search_vec":"'2.2.0':9 'aim':48 'allow':25 'bridg':12 'column':30 'current':7 'data':51,61 'datafram':23,29 'differ':32 'engin':70 'featur':42,69 'involv':54 'learn':16,19,35,60,65,68 'librari':47 'machin':18,67 'map':28 'method':20 'model':44 'panda':3,6,22,56,66 'preprocess':52,71 'provid':10 'recombin':40 'scikit':15,34,59,64 'scikit-learn':14,33,58,63 'sklearn':2,5 'sklearn-panda':1,4 'streamlin':50 'train':45 'transform':36,62 'user':26 'version':8 'workflow':53","created_at":"2026-04-16T17:03:15.842692+00:00","updated_at":"2026-04-16T17:03:15.842692+00:00","problems":{"verify_error":"Traceback (most recent call last):\n  File \"<string>\", line 1, in <module>\n  File \"/tmp/tmp10ka4dx8/venv/lib/python3.12/site-packages/sklearn_pandas/__init__.py\", line 6, in <module>\n    from .dataframe_mapper import DataFrameMapper  # NOQA\n    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/t"},"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"2.2.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/scikit-learn-contrib/sklearn-pandas","docs":null,"changelog":null,"pypi":"https://pypi.org/project/sklearn-pandas/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["ai-ml","data"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"import_fail","verified_at":"2026-07-03","last_verified":"2026-07-03","next_check":"2026-07-10","install_tag":null}}