Python | Pandas Series.diff() Last Updated : 20 Nov, 2018 Comments Improve Suggest changes Like Article Like Report Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Series.diff() is used to find difference between elements of the same series. The difference is sequential and depends on period parameter passed to diff() method. Syntax: Series.diff(periods=1) Parameters: periods: integer value, subtracts element before/after period from current element. Negative values are also accepted Return type: Series Example: In this example, two series are created from Python lists. diff() method is called on both series, one time with positive period and one time with negative value passed to period parameter. Python3 1== # importing pandas module import pandas as pd # importing numpy module import numpy as np # creating list list =[15, 2, 34, 12, 4, 0, 9, 7] # creating series series = pd.Series(list) # calling method with period 2 period2 = series.diff(2) # Passing Negative value to period # passing period of -1 period_1 = series.diff(-1) # display print('Diff with period 2:\n{}\n\ Diff with period -1:\n{}'.format(period2, period_1)) Output: Diff with period 2: 0 NaN 1 NaN 2 19.0 3 10.0 4 -30.0 5 -12.0 6 5.0 7 7.0 dtype: float64 Diff with period -1: 0 13.0 1 -32.0 2 22.0 3 8.0 4 4.0 5 -9.0 6 2.0 7 NaN dtype: float64 Explanation: In the first output with period 2, value at ith position were subtracted from (i+2)th position and stored at (i+2)th position. In second output, value at ith position were subtracted from values at (i-1)th position and stored at (i-1)th position. Note: First/Last n values in output series are NaN depending on sign of period.(First if period is positive and Last if negative where n is period). Comment More infoAdvertise with us Next Article Python | Pandas Series.eq() K Kartikaybhutani Follow Improve Article Tags : Technical Scripter Python Python-pandas Python pandas-series Python pandas-series-methods +1 More Practice Tags : python Similar Reads Python Pandas Series Pandas Series is a one-dimensional labeled array that can hold data of any type (integer, float, string, Python objects, etc.). It is similar to a column in an Excel spreadsheet or a database table. In this article we will study Pandas Series a powerful one-dimensional data structure in Python.Key F 5 min read Python | Pandas Series.eq() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas series.eq() is used to compare every element of Caller series with passed serie 3 min read Python | Pandas Series.eq() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas series.eq() is used to compare every element of Caller series with passed serie 3 min read Python | Pandas Series.ge() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas series.ge() is used to compare every element of Caller series with passed serie 3 min read Python | Pandas Series.ge() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas series.ge() is used to compare every element of Caller series with passed serie 3 min read Python | Pandas Series.le() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas series.le() is used to compare every element of Caller series with passed serie 3 min read Like