Merging two DataFrames

The error message indicates that df2 is of type pd.Series. You need to convert df2 .to_frame() as .merge() needs a pd.DataFrame() input (see docs):

df1.merge(df2[['*.S']].to_frame(), left_on='id', right_index=True)

while you probably also just could:

df1.merge(df2.to_frame(), left_on='id', right_index=True)

Alternatively, you can use pd.DataFrame.join() which accepts a pd.Series.

Leave a Comment