one hot encoding(given category column)

PHOTO EMBED

Mon Nov 18 2024 11:55:56 GMT+0000 (Coordinated Universal Time)

Saved by @wtlab

import pandas as pd

# Step 1.1: Convert the dictionary to a DataFrame
data = {
    'Category': ['A', 'B', 'A', 'C', 'B']
}
df = pd.DataFrame(data)

# Step 1.2: Apply One-Hot Encoding
df_encoded = pd.get_dummies(df, columns=['Category'])

# Step 1.3: Print the DataFrame with One-Hot Encoding
print(df_encoded)
content_copyCOPY