I am trying to place a method in a class that will replace null values with running average of non null values. Please refer to the code below:
class ElNinoData(object):
    # Your implementation here 
    add = 0
    counter = 0
    average = 0
    # methods
    def __init__(self , object):
        self.object = object
    def get_humidity(self):
        if not math.isnan(self.object['humidity']):  
            global add 
            global counter
            global average
            add += self.object['humidity']
            counter += 1
            average = add/counter
        else:
            self.object['humidity'] = average
        return self.object['humidity']
While executing this class in a method, I am getting the following error:
<ipython-input-40-c52c3ac6484b> in get_humidity(self)
     19             global average
     20 
---> 21             add += self.object['humidity']
     22             counter += 1
     23             average = add/counter
NameError: name 'add' is not defined
Could anyone please explain the error,I am relatively new to python?
 
     
     
     
    