---
title: subtract
description: "DataFrame.subtract method in PySpark: Return a new DataFrame containing rows in this DataFrame but not in another DataFrame."
canonical_url: https://docs.databricks.com/aws/en/pyspark/reference/classes/dataframe/subtract
---

# subtract

Return a new DataFrame containing rows in this DataFrame but not in another DataFrame.

## Syntax

```
subtract(other: "DataFrame")
```

## Parameters

| Parameter | Type      | Description                                    |
| --------- | --------- | ---------------------------------------------- |
| `other`   | DataFrame | Another DataFrame that needs to be subtracted. |

## Returns

`DataFrame`: Subtracted DataFrame.

## Notes

This is equivalent to `EXCEPT DISTINCT` in SQL.

## Examples

```python
df1 = spark.createDataFrame([("a", 1), ("a", 1), ("b", 3), ("c", 4)], ["C1", "C2"])
df2 = spark.createDataFrame([("a", 1), ("a", 1), ("b", 3)], ["C1", "C2"])
result_df = df1.subtract(df2)
result_df.show()
# +---+---+
# | C1| C2|
# +---+---+
# |  c|  4|
# +---+---+

df1 = spark.createDataFrame([(1, "A"), (2, "B")], ["id", "value"])
df2 = spark.createDataFrame([(2, "B"), (3, "C")], ["id", "value"])
result_df = df1.subtract(df2)
result_df.show()
# +---+-----+
# | id|value|
# +---+-----+
# |  1|    A|
# +---+-----+
```
