I have a pandas DataFrame with three columns:
x = [4,2,4,-4,-80,1]
y = [1,2,3,-10,50,1]
z = [3,4,-1,-3,0,-1]
df = pd.DataFrame({'x': x,'y': y, 'z':z})
And I need to create a function that returns the maximum value reached by the accumulative max function. In order to do this I try:
def get_max(DataFrame):
DataFrame['CumSum'] = DataFrame.cumsum()
print(max(DataFrame['CumSum']))
If I apply this function for the first time, by writing for example:
get_max(df['x'] )
it works correctly and it returns 10, but if I try to apply it a second time on df['x'] I get an error: ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Not sure about the error, I think that perhaps the problem occurs because I am trying to create a new column that already has been created thru this line:
DataFrame['CumSum'] = DataFrame.cumsum()
I would appreciate if someone could tell me if there is any way of solving this.
Thanks a lot in advance.