Challenge - 5 Problems
Concat Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of vertical stacking with concat()
What is the output DataFrame after stacking df1 and df2 vertically using
pd.concat([df1, df2])?Data Analysis Python
import pandas as pd df1 = pd.DataFrame({'A': [1, 2], 'B': [3, 4]}) df2 = pd.DataFrame({'A': [5, 6], 'B': [7, 8]}) result = pd.concat([df1, df2]) print(result)
Attempts:
2 left
💡 Hint
Remember that concat keeps original indices by default when stacking vertically.
✗ Incorrect
When stacking vertically with pd.concat, the default behavior keeps the original row indices from both DataFrames, so the result has duplicate indices 0 and 1.
❓ Predict Output
intermediate2:00remaining
Output of horizontal stacking with concat()
What is the output DataFrame after stacking df1 and df2 horizontally using
pd.concat([df1, df2], axis=1)?Data Analysis Python
import pandas as pd df1 = pd.DataFrame({'A': [1, 2]}) df2 = pd.DataFrame({'B': [3, 4]}) result = pd.concat([df1, df2], axis=1) print(result)
Attempts:
2 left
💡 Hint
Horizontal stacking aligns rows by index.
✗ Incorrect
Concatenating along axis=1 stacks columns side by side, matching rows by their index. Since both DataFrames have indices 0 and 1, the result has those rows with columns A and B.
❓ data_output
advanced2:00remaining
Result of concat() with ignore_index=True
What is the output DataFrame after stacking df1 and df2 vertically using
pd.concat([df1, df2], ignore_index=True)?Data Analysis Python
import pandas as pd df1 = pd.DataFrame({'X': [10, 20], 'Y': [30, 40]}) df2 = pd.DataFrame({'X': [50, 60], 'Y': [70, 80]}) result = pd.concat([df1, df2], ignore_index=True) print(result)
Attempts:
2 left
💡 Hint
ignore_index resets the row indices to a continuous range.
✗ Incorrect
Using ignore_index=True resets the row indices in the concatenated DataFrame to 0,1,2,... ignoring the original indices.
🔧 Debug
advanced2:00remaining
Identify the error in concat() usage
What error will this code raise when trying to concatenate df1 and df2 with mismatched columns without specifying join?
Data Analysis Python
import pandas as pd df1 = pd.DataFrame({'A': [1, 2]}) df2 = pd.DataFrame({'B': [3, 4]}) result = pd.concat([df1, df2]) print(result)
Attempts:
2 left
💡 Hint
Check how concat handles different columns by default.
✗ Incorrect
By default, concat stacks rows and includes all columns from both DataFrames, filling missing values with NaN. No error is raised.
🚀 Application
expert3:00remaining
Stacking DataFrames with different columns and resetting index
You have two DataFrames with different columns. Which option correctly stacks them vertically, includes all columns, fills missing values with NaN, and resets the index?
Data Analysis Python
import pandas as pd df1 = pd.DataFrame({'A': [1, 2], 'B': [3, 4]}) df2 = pd.DataFrame({'B': [5, 6], 'C': [7, 8]})
Attempts:
2 left
💡 Hint
Think about vertical stacking with all columns and resetting index.
✗ Incorrect
Option A stacks vertically (default axis=0), includes all columns (default join='outer'), fills missing with NaN, and resets index with ignore_index=True. Other options either stack horizontally or limit columns.