---
title: partitioning.bucket
description: "partitioning.bucket function in PySpark: A transform for any type that partitions by a hash of the input column."
canonical_url: https://docs.databricks.com/aws/en/pyspark/reference/functions/partitioning_bucket
---

# partitioning.bucket

A transform for any type that partitions by a hash of the input column.

> [!NOTE]
>
> This function can be used only in combination with `DataFrameWriterV2.partitionedBy` method.

## Syntax

```python
from pyspark.sql.functions import partitioning

partitioning.bucket(numBuckets, col)
```

## Parameters

| Parameter    | Type                        | Description                                 |
| ------------ | --------------------------- | ------------------------------------------- |
| `numBuckets` | `pyspark.sql.Column` or int | The number of buckets.                      |
| `col`        | `pyspark.sql.Column` or str | Target date or timestamp column to work on. |

## Examples

```python
from pyspark.sql.functions import partitioning
df.writeTo("catalog.db.table").partitionedBy(
    partitioning.bucket(42, "ts")
).createOrReplace()
```
