Calculate the expanding correlation.
If not supplied then will default to self and produce pairwise output.
If False then only matching columns between self and other will be used and the output will be a DataFrame. If True then all pairwise combinations will be calculated and the output will be a MultiIndexed DataFrame in the case of DataFrame inputs. In the case of missing elements, only complete pairwise observations will be used.
Include only float, int, boolean columns.
Added in version 1.5.0.
Return type is the same as the original object with np.float64 dtype.
See also
covSimilar method to calculate covariance.
numpy.corrcoefNumPy Pearson’s correlation calculation.
pandas.Series.expandingCalling expanding with Series data.
pandas.DataFrame.expandingCalling expanding with DataFrames.
pandas.Series.corrAggregating corr for Series.
pandas.DataFrame.corrAggregating corr for DataFrame.
Notes
This function uses Pearson’s definition of correlation (https://en.wikipedia.org/wiki/Pearson_correlation_coefficient).
When other is not specified, the output will be self correlation (e.g. all 1’s), except for DataFrame inputs with pairwise set to True.
Function will return NaN for correlations of equal valued sequences; this is the result of a 0/0 division error.
When pairwise is set to False, only matching columns between self and other will be used.
When pairwise is set to True, the output will be a MultiIndex DataFrame with the original index on the first level, and the other DataFrame columns on the second level.
In the case of missing elements, only complete pairwise observations will be used.
Examples
>>> ser1 = pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])
>>> ser2 = pd.Series([10, 11, 13, 16], index=['a', 'b', 'c', 'd'])
>>> ser1.expanding().corr(ser2)
a NaN
b 1.000000
c 0.981981
d 0.975900
dtype: float64
© 2008–2011, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
© 2011–2025, Open source contributors
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/2.3.0/reference/api/pandas.core.window.expanding.Expanding.corr.html