I want to know if there is any possibility that the pandas apply function (applied row-wise) will operate on 2 rows at the same time. Say I have the following class:
class Counter():
def __init__(self):
self.count = 0
self.value = None
def add(self, value):
self.value = value
time.sleep(2) # because my actual function is more complicated
self.count += self.value
return self.value
And I use the same instance of it within an apply. Will the following operation always return the same results?
df = pd.DataFrame({'A': [1,2,3,4,5]})
counter = Counter()
assert df['A'].apply(counter.add).tolist() == [1,2,3,4,5]
assert counter.count == 15