In Python, when performing an inner merge on one column, why would a shared value from that column not generate output for corresponding row values?

Viewed 23

I'm following along with the 2017 (Second Edition) O'Reilly Python for Data Analysis book (which uses Python 3.6) and encountered this basic code for an inner merge (with the output as I see it, having now tried in multiple shells, and not how the output appears in the book):

import pandas as pd

df1 = pd.DataFrame({'key': ['b', 'b', 'a', 'c', 'a', 'a',' b'], 'data1':range(7)})
df2 = pd.DataFrame({'key': ['a', 'b', 'd'], 'data2': range(3)})

print(df1)
print(df2)
pd.merge(df1, df2)

enter image description here

Yet the book has a result (from identical code) yielding:

enter image description here

Why would the row for b with data1 as 6 and data2 as 1 be cut? If b is a shared key value, my understanding was that you would see a row for that key value with corresponding data1 and data2 values?

0 Answers
Related