one_hot_encoding(given_category_column) EXTERNAL

PHOTO EMBED

Tue Nov 19 2024 04:44:40 GMT+0000 (Coordinated Universal Time)

Saved by @login123

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