0

I'm trying to calculate rolling window correlation following How to calculate Rolling Correlation with pandas?. I have a dataset with two columns and a datetime index.

+---------------------+---------------------+---------------------+
|                     |   temperature_pair1 |   temperature_pair2 |
|---------------------+---------------------+---------------------|
| 2019-04-16 09:06:00 |               22.69 |               22.69 |
| 2019-04-16 09:07:00 |               22.69 |               22.69 |
| 2019-04-16 09:08:00 |               22.69 |               22.69 |
| 2019-04-16 09:09:00 |               22.75 |               22.69 |
| 2019-04-16 09:10:00 |               22.69 |               22.69 |
| 2019-04-16 09:11:00 |               22.69 |               22.75 |
| 2019-04-16 09:12:00 |               22.75 |               22.75 |
| 2019-04-16 09:13:00 |               22.75 |               22.75 |
| 2019-04-16 09:14:00 |               22.75 |               22.75 |
| 2019-04-16 09:15:00 |               22.75 |               22.75 |
+---------------------+---------------------+---------------------+

I'm applying the same methods shown in the question, foi.temperature_pair1.rolling(window_size).corr(foi.temperature_pair2), but the resulting dataframe has values outside of the range [-1, 1]. What exactly am I missing?

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
  • 1
    Can you copy your actual data in the post and not as an image? – NYC Coder May 14 '20 at 21:16
  • Please [provide a reproducible copy of the DataFrame with `df.head(10).to_clipboard(sep=',')`](https://stackoverflow.com/questions/52413246/how-to-provide-a-copy-of-your-dataframe-with-to-clipboard) – Trenton McKinney May 14 '20 at 21:21
  • That can't be copied easily back into a dataframe. However, the link I gave, also shows how to get a reproducible dataset from colab. – Trenton McKinney May 15 '20 at 00:53
  • Do the following: **1:** `foi_corr = pd.DataFrame(foi.temperature_pair1.rolling(10).corr(foi.temperature_pair2)).rename(columns={0: 'corr'})` **2:** `print(foi_corr.min())` **3:** `print(foi_corr.max())` **4:** `foi_corr.plot()` **5:** Edit the question and add the information from these instructions. You can change `10` to your preferred window size, but include that information back in the question. – Trenton McKinney May 15 '20 at 01:12
  • Also, can you share a link to this dataset? – Trenton McKinney May 15 '20 at 01:21

0 Answers0