Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to merge two dataframes on the 'id' column.
Data Analysis Python
merged_df = df1.merge(df2, on=[1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a column that doesn't exist in both dataframes.
Forgetting to put quotes around the column name.
✗ Incorrect
We merge datasets on the common column 'id' to combine matching rows.
2fill in blank
mediumComplete the code to concatenate two dataframes vertically.
Data Analysis Python
combined_df = pd.concat([df1, df2], axis=[1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using axis=1 which stacks columns instead of rows.
Using an invalid axis number.
✗ Incorrect
axis=0 stacks dataframes vertically, adding rows.
3fill in blank
hardFix the error in the code to merge dataframes with an inner join.
Data Analysis Python
result = df1.merge(df2, how=[1], on='user_id')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'outer' which keeps all rows, not just matching ones.
Using 'left' or 'right' which keep all rows from one dataframe only.
✗ Incorrect
An inner join keeps only rows with matching keys in both dataframes.
4fill in blank
hardFill both blanks to create a dictionary of word lengths for words longer than 3 letters.
Data Analysis Python
lengths = {word: [1] for word in words if len(word) [2] 3} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length.
Using '<' instead of '>' in the condition.
✗ Incorrect
We map each word to its length if the word length is greater than 3.
5fill in blank
hardFill all three blanks to create a filtered dictionary with uppercase keys and values greater than 0.
Data Analysis Python
result = [1]: [2] for k, v in data.items() if v [3] 0}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'k' instead of 'k.upper()' for keys.
Using '<' instead of '>' in the condition.
Using keys as values or vice versa.
✗ Incorrect
Keys are uppercase, values are original, filtered by values greater than zero.