---
title: cov (DataFrameStatFunctions)
description: "DataFrameStatFunctions.cov method in PySpark: Calculates the sample covariance for the given columns, specified by their names, as a double value."
canonical_url: https://docs.databricks.com/gcp/en/pyspark/reference/classes/dataframestatfunctions/cov
---

# cov (DataFrameStatFunctions)

Calculates the sample covariance for the given columns, specified by their names, as a double value. `DataFrame.cov` and `DataFrameStatFunctions.cov` are aliases of each other.

## Syntax

```
cov(col1, col2)
```

## Parameters

| Parameter | Type | Description                    |
| --------- | ---- | ------------------------------ |
| `col1`    | str  | The name of the first column.  |
| `col2`    | str  | The name of the second column. |

## Returns

`float`

## Examples

```python
df = spark.createDataFrame([(1, 12), (10, 1), (19, 8)], ["c1", "c2"])
df.stat.cov("c1", "c2")
# -18.0

df = spark.createDataFrame([(11, 12), (10, 11), (9, 10)], ["small", "bigger"])
df.stat.cov("small", "bigger")
# 1.0
```
