I basically have a column of values that I want to check are valid. I want to make a new column that gives back true or false for validity. The values are valid when they are found in the lookup of another two columns, which comprise the key and values for a dictionary.
Here, my values are exams. An EXAM
are only valid if they land at a scoring site or a DBN
that can score them, for instance, if 11X000 can score Math, and this is a Math exam that landed at 11X000, it's a Valid Site
.
See the screenshots, the first image is what I'm trying to replicate in Python, and the second image is the dictionary.
In my code I made a dictionary for {site:exam}
and am trying to check validity for all given records.
Sites_To_Exams_Dict = Sites_To_Exams_df.groupby('DBN')['ALL EXAMS'].apply(list).to_dict()
MaterialsReport_df['Valid Site'] = np.where(MaterialsTracking_df['EXAM'] in Sites_To_Exams_Dict.get(MaterialsReport_df['Scoring Site Including X']),
"Y", "N")
Unfortunately this gives the error
TypeError: 'Series' objects are mutable, thus they cannot be hashed
I would appreciate any different approaches or bug fix to the code above. Thanks!