---
title: clusterBy (DataFrameWriterV2)
description: "DataFrameWriterV2.clusterBy method in PySpark: Clusters the data by the given columns to optimize query performance."
canonical_url: https://docs.databricks.com/aws/en/pyspark/reference/classes/dataframewriterv2/clusterBy
---

# clusterBy (DataFrameWriterV2)

Clusters the data by the given columns to optimize query performance.

## Syntax

```
clusterBy(col, *cols)
```

## Parameters

| Parameter | Type          | Description                    |
| --------- | ------------- | ------------------------------ |
| `col`     | str           | The first clustering column.   |
| `*cols`   | str, optional | Additional clustering columns. |

## Returns

`DataFrameWriterV2`
