---
title: cast
description: "Column.cast method in PySpark: Convert the column to a different data type."
canonical_url: https://docs.databricks.com/aws/en/pyspark/reference/classes/column/cast
---

# cast

Convert the column to a different data type.

## Syntax

```python
cast(dataType)
```

## Parameters

| Parameter  | Type            | Description      |
| ---------- | --------------- | ---------------- |
| `dataType` | DataType or str | Target data type |

## Returns

Column

## Examples

Cast with a string type name:

```python
from pyspark.sql.types import StringType
df = spark.createDataFrame(
     [(2, "Alice"), (5, "Bob")], ["age", "name"])
df.select(df.age.cast("string").alias('ages')).collect()
```

```Output
# [Row(ages='2'), Row(ages='5')]
```

Cast with a DataType instance:

```python
from pyspark.sql.types import StringType
df = spark.createDataFrame(
     [(2, "Alice"), (5, "Bob")], ["age", "name"])
df.select(df.age.cast(StringType()).alias('ages')).collect()
```

```Output
# [Row(ages='2'), Row(ages='5')]
```
