I am trying to perform a daily reconciliation which will check a master dataset in a pandas dataframe, for the existence various combinations in another dataset (the reconciliation key), which contains wildcards.
Here is an illustrative representation of the issue (not using real information from my rec):
Master Dataset
FirstName | LastName | Occupation | Gender |
---|---|---|---|
Angela | Norris | Firefighter | Female |
Angela | Thompson | Teacher | Female |
Ben | Johnson | Police Officer | Male |
Ben | Peterson | Solicitor | Male |
Charlie | Davies | Nurse | Male |
Debbie | Smith | Lawyer | Female |
Reconciliation Key
FirstName | LastName | Occupation | Gender |
---|---|---|---|
Angela | * | * | * |
Ben | Johnson | * | Male |
Debbie | * | * | Female |
So what I am trying to do here is find in the master dataset:
- Any records where FirstName = Angela (with three wildcards for LastName, Occupation, Gender)
- Any records where FirstName = Ben, LastName = Johnson and Gender = Male (with one wildcard on Occupation)
- Any records where FirstName = Debbie and Gender = Female (with two wildcards for LastName and Occupation)
I cannot work out how to do this task... I would normally create a unique key with the combinations of FirstName, LastName, Occupation and Gender, and then merge the two datasets, but with wildcards, this isn't working for me.
I also tried a cartesian product (which I could later filter), but the size of the dataset I am working with resulted in a memory issue, so that wasn't working either.
Ideally, the output of the check would give this table (i.e. showing rows in the master dataset that meet the criteria in the reconciliation key):
FirstName | LastName | Occupation | Gender |
---|---|---|---|
Angela | Norris | Firefighter | Female |
Angela | Thompson | Teacher | Female |
Ben | Johnson | Police Officer | Male |
Debbie | Smith | Lawyer | Female |