Python | Pandas Series.cov() to find Covariance Last Updated : 08 Oct, 2021 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.cov() is used to find covariance of two series. In the following example, covariance is found using both Pandas method and manually ways and the answers are then compared. To learn more about Covariance, click here. Syntax: Series.cov(other, min_periods=None)Parameters: other: Other series to be used in finding covariance min_periods: Minimum number of observations to be taken to have a valid resultReturn type: Float value, Returns covariance of caller series and passed series Example :In this example, two lists are made and converted to series using Pandas .Series() method. The average if both series is found and a function is created to find Covariance manually. Pandas .cov() is also applied and results from both ways are stored in variables and printed to compare the outputs. Python3 import pandas as pd # list 1 a = [2, 3, 2.7, 3.2, 4.1] # list 2 b = [10, 14, 12, 15, 20] # storing average of a av_a = sum(a)/len(a) # storing average of b av_b = sum(b)/len(b) # making series from list a a = pd.Series(a) # making series from list b b = pd.Series(b) # covariance through pandas method covar = a.cov(b) # finding covariance manually def covarfn(a, b, av_a, av_b): cov = 0 for i in range(0, len(a)): cov += (a[i] - av_a) * (b[i] - av_b) return (cov / (len(a)-1)) # calling function cov = covarfn(a, b, av_a, av_b) # printing results print("Results from Pandas method: ", covar) print("Results from manual function method: ", cov) Output: As it can be seen in output, the output from both ways is same. Hence this method is useful when finding co variance for large series. Results from Pandas method: 2.8499999999999996 Results from manual function method: 2.8499999999999996 Comment More infoAdvertise with us Next Article Python | Pandas Series.cov() to find Covariance K Kartikaybhutani Follow Improve Article Tags : Python Python-pandas Python pandas-series Python pandas-series-methods Practice Tags : python Similar Reads Python | Pandas Series.to_frame() Pandas series is a One-dimensional ndarray with axis labels. The labels need not be unique but must be a hashable type. The object supports both integer- and label-based indexing and provides a host of methods for performing operations involving the index. Pandas Series.to_frame() function is used t 3 min read Python | Pandas Series.to_dict() Pandas series is a One-dimensional ndarray with axis labels. The labels need not be unique but must be a hashable type. The object supports both integer- and label-based indexing and provides a host of methods for performing operations involving the index. Pandas Series.to_dict() function is used to 3 min read Python | Pandas Series.corr() Pandas series is a One-dimensional ndarray with axis labels. The labels need not be unique but must be a hashable type. The object supports both integer- and label-based indexing and provides a host of methods for performing operations involving the index. Pandas Series.corr() function compute the c 3 min read Python | Pandas Dataframe/Series.dot() 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.dot()The dot() method is used to compute the dot product between DataFr 6 min read Python | Pandas Series.from_array() Pandas series is a One-dimensional ndarray with axis labels. The labels need not be unique but must be a hashable type. The object supports both integer- and label-based indexing and provides a host of methods for performing operations involving the index. Pandas Series.from_array() function constru 2 min read Like