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)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter