A foreign key is a column whose values reference existing primary-key values in another dataset. It links records while preserving a clear lineage between DataFrames. section 2.5.4
Orders and payments
A customer dataset can use customer identifiers as primary keys, while an orders dataset references those identifiers. Similarly, order_id can be a primary key in df_orders and a foreign key in df_order_payments. Checking the relationship reveals missing references, including one violation in the example. section 2.5.4
Listing 2.2 Identifying foreign key violations
foreign_key_violations =
df_orders[~df_orders['order_id'].isin(df_order_payments['order_id'])]
if not foreign_key_violations.empty:
print("Foreign key violations found:")
print(foreign_key_violations)
# Handle violations (e.g., drop rows or correct the foreign key values)
Run the listing to identify rows in df_orders whose order_id values do not appear in df_order_payments, then inspect and resolve the violations. section 2.5.4

















