Complete the code to import the pandas library.
import [1] as pd
We use import pandas as pd to work with dataframes easily.
Complete the code to create a DataFrame from a dictionary.
df = pd.DataFrame({'color': ['red', 'blue', 'green']})
print(df.[1]())tail() to see the first rowsinfo() which shows summary infohead() shows the first rows of the DataFrame.
Fix the error in the code to apply one-hot encoding using pandas.
one_hot = pd.get_dummies(df['color'], [1]=True) print(one_hot)
drop_first=True avoids dummy variable trap by dropping the first category.
Fill both blanks to create a one-hot encoded DataFrame and join it with the original.
one_hot = pd.get_dummies(df['color'], [1]=False) df_new = df.[2](one_hot, axis=1) print(df_new)
append which adds rows, not columnsmerge which requires keysUse drop_first=False to keep all dummies, then concat to join columns.
Fill all three blanks to create a one-hot encoded DataFrame, drop the original column, and display the result.
one_hot = pd.get_dummies(df['color'], [1]=True) df = df.[2]('color', axis=[3]) df_final = pd.concat([df, one_hot], axis=1) print(df_final)
axis=0 which drops rows instead of columnsWe drop the first dummy column, remove the original 'color' column with drop along columns (axis=1), then join the dummies.
