I am trying to loop through a Series data type which was randomly generated from an existing data set to serve as a training data set). Here is the output of my Series data set after the split:
Index     data
0         1150
1         2000
2         1800
.         .
.         .
.         .
1960      1800
1962      1200
.         .
.         .
.         .
20010     1500
There is no index of 1961 because the random selection process to create the training data set removed it. When I try to loop through to calculate my residual sum squares it does not work. Here is my loop code:
def ResidSumSquares(x, y, intercept, slope):    
    out = 0
    temprss = 0
    for i in x:
        out = (slope * x.loc[i]) + intercept
        temprss = temprss + (y.loc[i] - out)
    RSS = temprss**2
    return print("RSS: {}".format(RSS))
KeyError: 'the label [1961] is not in the [index]'
I am still very new to Python and I am not sure of the best way to fix this.
Thank you in advance.
 
     
     
    