0

I am interested to calculated the cross correlation between two columns in a table, the index is the date. I would like to know what is the lag at the best cross-correlation value.

I am using this: dataframe1.corr(dataframe2, method='pearson',min_periods=1)

For example in matlab, one could do: [r,lags] = xcorr(x,y), and lags is a vector with the lags at which the correlations are computed. I would like to get the same thing with pandas. The dataframe.corr only outputs the cross-correlation value between 2 columns.

dataframe1: 
1994-10-31 0
1994-11-30 23604
1994-12-31 1880
1995-01-31 24566
....
2017-07-31 2224


dataframe2:
1994-10-31 0
1994-11-30 0
1994-12-31 36997
1995-01-31 7444
....
2017-07-31 9711

I want to know how much is dataframe2 shifted, in order to give the maximum cross correlation value.

Kaiba Wong
  • 11
  • 3
  • I'm not sure how you expect us to help you with one line of code and a sentence on how good you are at matlab. How about showing us some data... Print out the first few rows of your dataframe, add it to your question. Ideally, we want your expected output as well. Can you do that please? – cs95 Nov 07 '17 at 16:17
  • Looks like you need `rolling` with `corr` – BENY Nov 07 '17 at 16:22
  • Any suggestions will be appreciated - thank you! – Kaiba Wong Nov 07 '17 at 16:37
  • Check this [answer](https://stackoverflow.com/a/37215839/7732344) from another post. – romulomadu Feb 06 '18 at 00:14

0 Answers0