0

I have a data frame temps that looks like this

enter image description here

And I am trying to apply a shift of 1 and then a rolling function with window 2 and finally taking the mean of the rolling data frame, see below code for reference,

shifted = temps.shift(1)
window = shifted.rolling(2)
means = window.mean()

but I am getting an error like below:

DataError: No numeric types to aggregate

when I print the window, I get an output like below":

enter image description here

Can someone please tell me why I am receiving a DataError on calculating mean() of rolling output? and is the rolling function used correctly here?

NJ1
  • 67
  • 1
  • 8
  • 1
    can you try this line and see if you get the same error (assuming you've imported `pd` and `np`): `pd.DataFrame(np.random.random(3650)).shift(1).rolling(2).mean()` – tdy May 02 '21 at 07:34
  • 1
    @tdy : I ran the above line and it ran successfully, but when I put my dataframe temps in place of np.random.random(3650) it again starts giving me the same error : DataError: No numeric types to aggregate Is there something I need to fix with the dataframe? – NJ1 May 02 '21 at 10:17
  • 1
    try explicitly converting to `float` first. this isn't necessary on my end even if there are non-numerics in the data, but maybe it's a version issue: `temps.astype(float).shift(1).rolling(2).mean()` – tdy May 02 '21 at 10:26
  • 1
    @tdy - Thanks, it worked!! all it required was float conversion.. Thanks!! – NJ1 May 02 '21 at 10:56

0 Answers0