Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Referencing a fixed cell
#1
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!
Reply
#2
Always show unaltered and complete traceback (in bbcode error tags)
In addition, please post enough of a snippet that it is runnable.
Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  name 'lblstatus' is not defined when referencing a label KatManDEW 4 2,833 Apr-21-2022, 12:33 PM
Last Post: KatManDEW
  Dictionary Referencing nickdavis2017 1 2,208 Nov-20-2021, 06:24 PM
Last Post: deanhystad
  Referencing string names in df to outside variables illmattic 1 1,917 Nov-16-2021, 12:47 PM
Last Post: jefsummers
Sad need help in referencing a list n00bdev 2 2,481 Nov-01-2020, 12:06 PM
Last Post: buran
  Issue referencing new instance from other class nanok66 3 2,987 Jul-31-2020, 02:07 AM
Last Post: nanok66
  referencing another method in a class Skaperen 6 3,921 Jul-02-2020, 04:30 AM
Last Post: Skaperen
  Theory behind referencing a dictionary rather than copying it to a list sShadowSerpent 2 2,784 Mar-24-2020, 07:18 PM
Last Post: sShadowSerpent
  fixed width numbers Skaperen 15 12,355 May-27-2019, 09:42 AM
Last Post: Skaperen
  "not defined" error in function referencing a class Exsul 2 4,429 Mar-27-2019, 11:59 PM
Last Post: Exsul
  Prevent Variable Referencing Th3Eye 4 3,918 Oct-03-2018, 07:01 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020