Are the id columns similar to primary keys in SQL?


#1

Question

in the context of this exercise, are id columns similar to primary keys in SQL?

Answer

They are similar, but their functionality is not the same as for SQL.

In SQL, primary keys provide a constraint so that the values in a column must be unique. It can throw an error if the values are not unique.

In Pandas however, there are not really any primary key constraints, as values under a column like product_id can still have duplicate values.

Instead, when working with dataframes, we would need to designate some column to act as a “primary key”, and make sure that any duplicates are removed from or prevented for the column.