pandas rolling(n).corr() stuck on 1 no matter what the data is? [closed]

I’m not sure what you’re trying to do, but foo.rolling(n).corr() where foo is a linear sequence gives you the correlation of a linear sequence and its shifted self (so equal rate of increase), so the correlation is by definition 1. See for yourself:

import pandas as pd
d = {"one":[1, 2, 3, 4, 5, 6, 7, 8]}
data=pd.DataFrame(d)
compute = data["one"].rolling(3).corr()
for i in data["one"].rolling(3):
    print(i)

returns:

Name: one, dtype: int64
0    1
1    2
Name: one, dtype: int64
0    1
1    2
2    3
Name: one, dtype: int64
1    2
2    3
3    4
Name: one, dtype: int64
2    3
3    4
4    5
Name: one, dtype: int64
3    4
4    5
5    6
Name: one, dtype: int64
4    5
5    6
6    7
Name: one, dtype: int64
5    6
6    7
7    8
Name: one, dtype: int64

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top