Skip to content
Advertisement

How to check if one column maps to specific value and vice verse?

I have a data frame with the following columns:

JavaScript

First, I want to check that all 32835 values in the “zip_code” column match to a “part_no” with the following pattern, 01xxxxxx, where the Xs are numbers. Then, I want to make sure all 01xxxxxx part_no correspond to a 32835 “zip_code.” If not, I would like to return a list of “lot_no” for the ones that fail the check, or True if the whole dataframe passes.

In this example, the output should be [3, 4].

Advertisement

Answer

Use boolean mask:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement