2

I am looking at someones code and am relatively new to Python so if possible would like some advice.

The code below is looking at a couple of columns (Main department and Current organisation) in a dataframe called rawDatabase and writing to a file any records that do not have a valid Main department and Current organisation pairing as laid out in the validationLists (val)

I am trying to execute the code and it fails at a line with a ~ symbol in it:

errors = rawDatabase[~mask]

The whole method for context is:

def checkDeptOrgMapping(rawDatabase,validationLists,filename,filepath):

    val = validationLists[['Main department', 'Current organisation']].apply(tuple, 1).values


    if ~rawDatabase[['Main department', 'Current organisation']].apply(tuple, 1).isin(val).all():

        mask = rawDatabase[['Main department', 'Current organisation']].apply(tuple, 1).isin(val)


        errors = rawDatabase[~mask]

        errors = errors[['Identifier','Main department', 'Current organisation']]

        errors['Error Type'] = 'Department and Organisational names do not match'
        #print(errors)

        saveToCSV(errors,'errors.csv',filepath)

My question is two fold where hopefully the first part will answer the second part. The first part is, in the context of the above what is the ~ symbol actually doing and the second part is how can I get the code to run.

Many thanks

Stacey
  • 4,825
  • 17
  • 58
  • 99

0 Answers0