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

Actionable SWOT Analysis

For annual strategic planning or before a fundraising round

362
📊Analyse de donnéesIntermediateAll AIs

Stock and inventory data analysis

Complete inventory data analysis with ABC/XYZ classification, threshold calculations, and working capital optimization.

663
📊Analyse de donnéesIntermediateAll AIs

Retention Analysis

Improve user retention

334

Engineer date features

Extract features from datetime columns

403