HelpData Analysis with Python
pandas merge keeps duplicating rows
Omar Haddad
Posted Yesterday
I'm merging orders with customers and the result has more rows than the orders table. I'm using `how="left"` on customer_id. What am I missing?
Omar Haddad
Posted Yesterday
I'm merging orders with customers and the result has more rows than the orders table. I'm using `how="left"` on customer_id. What am I missing?
Your customers table has duplicate customer_id values, so each order matches more than once. Run customers.customer_id.duplicated().sum() first, and pass validate="many_to_one" to merge so pandas warns you next time.
Showing 4 of 9 · sorted by oldest