Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the pandas library.
Data Analysis Python
import [1] as pd
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing numpy instead of pandas
Forgetting to use 'as pd'
✗ Incorrect
We use import pandas as pd to work with dataframes easily.
2fill in blank
mediumComplete the code to create a DataFrame from a dictionary.
Data Analysis Python
df = pd.DataFrame({'color': ['red', 'blue', 'green']})
print(df.[1]()) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
tail() to see the first rowsUsing
info() which shows summary info✗ Incorrect
head() shows the first rows of the DataFrame.
3fill in blank
hardFix the error in the code to apply one-hot encoding using pandas.
Data Analysis Python
one_hot = pd.get_dummies(df['color'], [1]=True) print(one_hot)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter names like 'drop' or 'remove'
Not using any parameter and causing redundant columns
✗ Incorrect
drop_first=True avoids dummy variable trap by dropping the first category.
4fill in blank
hardFill both blanks to create a one-hot encoded DataFrame and join it with the original.
Data Analysis Python
one_hot = pd.get_dummies(df['color'], [1]=False) df_new = df.[2](one_hot, axis=1) print(df_new)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
append which adds rows, not columnsUsing
merge which requires keys✗ Incorrect
Use drop_first=False to keep all dummies, then concat to join columns.
5fill in blank
hardFill all three blanks to create a one-hot encoded DataFrame, drop the original column, and display the result.
Data Analysis Python
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)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
axis=0 which drops rows instead of columnsNot dropping the original column before concatenation
✗ Incorrect
We drop the first dummy column, remove the original 'color' column with drop along columns (axis=1), then join the dummies.