'How to make my buffer operation in a python class faster/more efficient?
I have a variable in a Class.
self.temp = pd.DataFrame(columns = ['A', 'B'])
Not a coder by profession. Wrote a piece of code. Was running fairly fast. Made changes. Much slower now.
Added a variable in a class whose sole purpose was to be a buffer for operations on data from a csv. The following operations are carried out on it.
self.temp.loc[len(self.temp.index)] = [self.CALC.A.iloc[-1], self.CALC.B.iloc[-1]]self.RESULT.loc[len(self.ATR.index)] = [self.temp.A.iloc[-1], self.temp.B.iloc[-1]]self.temp = self.temp[0:0]
Is there a more efficient way to do this? Currently it is very time consuming (200,000+ rows to process).
Another line of code added was
self.RESULT.drop(self.RESULT.tail(1).index,inplace=True)
Any and all ways to make the code more efficient after these changes will be much appreciated. :)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
