Python Forum

Full Version: Referencing a fixed cell
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This line of code is giving a Traceback:
ES_skel['Pct_Return']=100*(ES_skel['Close']-ES_skel['Close'][0])/ES_skel['Close'][0]
The IndexError is "index 0 is out of bounds for axis 0 with size 0."

This df currently has only column ('Close') with a datetime index. What I'm trying to do is create a new column 'Pct_Return' that reflects percentage change since the beginning of the period. I'm therefore trying to fix the first date by selecting the zero index of the column.

What did I do wrong? Thanks!
Always show unaltered and complete traceback (in bbcode error tags)
In addition, please post enough of a snippet that it is runnable.
I figured it out with this line:
ES_skel['Cum_Return'] = (1 + ES_skel['Daily_Return']).cumprod() - 1
I was trying to reinvent the wheel, I guess.

Sorry for the insufficient info. I have another question about this--I'll include it all there.