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
Answer 3 questions and Léa tailors the prompt to your situation.
Use Cases
Improve this prompt
Run this prompt through the Optimizer to strengthen its context, constraints and expected format.
Improve this prompt with the OptimizerComments
- 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.