Python pandas index error Encountred an index error when trying to run the code found here.
The error occurs in section In[10]:
for n in range(len(dominantTheta)):
    shift = dominantTheta[n]
    regressionDelta += dominantAmp[n] * np.cos(n * np.array(range(len(df))) + shift)

Error message:
Traceback (most recent call last):
  File &quot;C:/Users/xxx/Desktop/Python Workspace/DSP.py&quot;, line 62, in &lt;module&gt;
    shift = dominantTheta[n]
  File &quot;C:\Users\xxx\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\series.py&quot;, line 868, in __getitem__
    result = self.index.get_value(self, key)
  File &quot;C:\Users\xxx\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\indexes\base.py&quot;, line 4375, in get_value
    tz=getattr(series.dtype, 'tz', None))
  File &quot;pandas\_libs\index.pyx&quot;, line 81, in pandas._libs.index.IndexEngine.get_value
  File &quot;pandas\_libs\index.pyx&quot;, line 89, in pandas._libs.index.IndexEngine.get_value
  File &quot;pandas\_libs\index.pyx&quot;, line 132, in pandas._libs.index.IndexEngine.get_loc
  File &quot;pandas\_libs\hashtable_class_helper.pxi&quot;, line 987, in pandas._libs.hashtable.Int64HashTable.get_item
  File &quot;pandas\_libs\hashtable_class_helper.pxi&quot;, line 993, in pandas._libs.hashtable.Int64HashTable.get_item
KeyError: 0

I have the latest versions of numpy and pandas installed, and using Python 3.6
In that section, within the for-loop, n is an integer (you loop over a range().

If you use the square brackets to access the Pandas DataFrame (or a Series, in this case), you are trying to access the index of the table. In this case, the index is a timestamp - have a look at the df in section Out [7].

So you need to get values by timestamp, or to use the row number itself, you must do as Vaalizaadeh said in a comment and use the .iloc accessor to the pandas object.

So just change shift = dominantTheta[n] to this: shift = dominantTheta.iloc[n].