Puzzle 22: Quick, Find a Phone Booth!

Let's solve a puzzle based on merging pandas DataFrames.

We'll cover the following

Guess the output

Try to guess the output of the code below:

Press + to interact
import pandas as pd
df1 = pd.DataFrame({
'id': [1, 2, 3],
'name': ['Clark Kent', 'Diana Prince', 'Bruce Wayne'],
})
df2 = pd.DataFrame({
'id': [2, 1, 4],
'hero': ['Wonder Woman', 'Superman', 'Aquaman'],
})
df = pd.merge(df1, df2, on='id')
print(df)

Quiz

Q

What is the output of the code above?

A)
    id   name            hero

0   1    Clark Kent      Wonder Woman

1   2    Diana Prince    Superman
B)
    id   name            hero

0   1    Clark Kent      Superman

1   2    Diana Prince    Wonder Woman
C)
    id   name            hero

0   1    Clark Kent      Wonder Woman

1   2    Diana Prince    Superman

2   3    Bruce Wayne     Aquaman
D)

IndexError

Get hands-on with 1300+ tech skills courses.