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.
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)
other: Other series to be used in finding covariance
min_periods: Minimum number of observations to be taken to have a valid result
Return type: Float value, Returns covariance of caller series and passed series
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 Covarience manually. Pandas
.cov() is also applied and results from both ways are stored in variables and printed to compare the outputs.
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
- Python | Pandas Series.str.find()
- Python | Pandas series.cummax() to find Cumulative maximum of a series
- Python | Pandas Series.cummin() to find cumulative minimum of a series
- Python | Pandas series.cumprod() to find Cumulative product of a Series
- Python | Pandas Series.cumsum() to find cumulative sum of a Series
- Python | pandas.map()
- Python | Pandas Series.mod()
- Python | Pandas.CategoricalDtype()
- Python | Pandas DatetimeIndex.day
- Python | Pandas DatetimeIndex.second
- Python | Pandas Dataframe.iat[ ]
- Python | Pandas Dataframe.at[ ]
- Python | Pandas.pivot_table()
- Python | Pandas Series.str.len()
- Python | Pandas Series.all()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.