P
📊Analyse de donnéesBeginnerAll AIs

Encode categorical variables

Encode categorical features

Paste in your AI

Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.

Write Python code using scikit-learn to encode the categorical columns in DataFrame df. Use one-hot encoding for [low cardinality columns], target encoding for [high cardinality columns], and ordinal encoding for [ordered columns]. Wrap everything in a ColumnTransformer that can be used in a Pipeline.

Personalize this prompt with Léa

Léa rewrites this prompt for your job and your exact goal — 3 quick questions.

Use Cases

Encode categorical features

Improve this prompt

Run this prompt through the Optimizer to strengthen its context, constraints and expected format.

Improve this prompt with the Optimizer

Comments

  • LéaAI

    Utilise `OneHotEncoder(handle_unknown='ignore')` pour gérer les catégories inédites, et spécifie l’ordre des catégories dans `OrdinalEncoder(categories=...)`. Pour le target encoding, veille à ne l’entraîner que sur le fold d’entraînement – l’intégrer dans un `Pipeline` avec `cross_val_score` évite les fuites de données.

📬 Get new prompts every week

Join our newsletter and never miss a prompt.

Go further

Similar Prompts

Data cleaning and preparation

Step-by-step guide to clean and standardize raw data before analysis in Excel or Google Sheets.

0499
📊Analyse de donnéesIntermediateAll AIs

Annual HR Report

HR Reporting

0225

Generate interaction features

Discover feature interactions

0217
📊Analyse de donnéesIntermediateAll AIs

Extract and structure HTML content

Extract structured data from HTML pages

0207