0

I have two dataframes: df_transactions & df_custdemo

I want to merge the two on df_transactions. (i.e. all the customer demographics data should merge onto the transactions data). The merge is done on customer_id, however the index for df_transactions = transaction_id.

When I merge, the final table result does not have the transaction_id column. How can i merge to also get that?

I have tried:

df_custdemo_transactions = df_transactions.merge(df_custdemo, how='left', left_on='customer_id', right_on='customer_id', left_index=True)

and

df_custdemo_transactions = df_transactions.merge(df_custdemo, how='left', left_on='customer_id', right_on='customer_id')

But final result does not have the transaction_id yet.

Péter Leéh
  • 2,069
  • 2
  • 10
  • 23
Sana Shah
  • 5
  • 5

1 Answers1

0

Add the following line before the executing the merge statement.

 df_transactions.reset_index(inplace=True)