pyspark.sql.Column.cast

Column.cast(dataType)[source]

Casts the column into type dataType.

New in version 1.3.0.

Examples

>>> df.select(df.age.cast("string").alias('ages')).collect()
[Row(ages='2'), Row(ages='5')]
>>> df.select(df.age.cast(StringType()).alias('ages')).collect()
[Row(ages='2'), Row(ages='5')]