- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Write a program in Python to compute autocorrelation between series and number of lags
Assume, you have series and the result for autocorrelation with lag 2 is,
Series is: 0 2.0 1 10.0 2 3.0 3 4.0 4 9.0 5 10.0 6 2.0 7 NaN 8 3.0 dtype: float64 series correlation: -0.4711538461538461 series correlation with lags: -0.2933396642805515
Solution
To solve this, we will follow the steps given below −
Define a series
Find the series autocorrelation using the below method,
series.autocorr()
Calculate the autocorrelation with lag=2 as follows,
series.autocorr(lag=2)
Example
Let’s see the below code to get a better understanding,
import pandas as pd import numpy as np series = pd.Series([2, 10, 3, 4, 9, 10, 2, np.nan, 3]) print("Series is:\n", series) print("series correlation:\n",series.autocorr()) print("series correlation with lags:\n",series.autocorr(lag=2))
Output
Series is: 0 2.0 1 10.0 2 3.0 3 4.0 4 9.0 5 10.0 6 2.0 7 NaN 8 3.0 dtype: float64 series correlation: -0.4711538461538461 series correlation with lags: -0.2933396642805515
- Related Articles
- Write a program in Python to print the elements in a series between a specific range
- Write a program in Python to count the total number of integer, float and object data types in a given series
- Python Program to Input a Number n and Compute n+nn+nnn
- Compute the roots of a Chebyshev series in Python
- Compute the roots of a Laguerre series in Python
- Compute the roots of a Hermite series in Python
- Compute the roots of a Legendre series in Python
- Compute the roots of a Hermite_e series in Python
- Write a C program to find out the largest and smallest number in a series
- Write a program in Python to compute grouped data covariance and calculate grouped data covariance between two columns in a given dataframe
- Write a Python program to separate a series of alphabets and digits and convert them to a dataframe
- Write a program in Python to generate any random five prime numbers between 100 to 150 in a Series
- Write a program in Python to filter valid dates in a given series
- Write a program in Python to filter armstrong numbers in a given series
- Write a program in Python to verify kth index element is either alphabet or number in a given series

Advertisements