pandas.Series.autocorr#
- Series.autocorr(lag=1)[source]#
Compute the lag-N autocorrelation.
This method computes the Pearson correlation between the Series and its shifted self.
- Parameters:
- lagint, default 1
Number of lags to apply before performing autocorrelation.
- Returns:
- float
The Pearson correlation between self and self.shift(lag).
See also
Series.corrCompute the correlation between two Series.
Series.shiftShift index by desired number of periods.
DataFrame.corrCompute pairwise correlation of columns.
DataFrame.corrwithCompute pairwise correlation between rows or columns of two DataFrame objects.
plotting.autocorrelation_plotAutocorrelation plot for time series.
Notes
If the Pearson correlation is not well defined return ‘NaN’.
Values can differ from
pandas.plotting.autocorrelation_plot(), which uses the mean and variance of the whole Series rather than of the overlapping portions.Examples
>>> s = pd.Series([0.25, 0.5, 0.2, -0.05]) >>> s.autocorr() 0.10355... >>> s.autocorr(lag=2) -1.0
If the Pearson correlation is not well defined, then ‘NaN’ is returned.
>>> s = pd.Series([1, 0, 0, 0]) >>> s.autocorr() nan