pyspark.sql.Column.cast — PySpark 3.1.1 documentation
spark.apache.org › pysparkpyspark.sql.Column.cast — PySpark 3.1.1 documentation Getting Started User Guide API Reference Development Migration Guide Spark SQL Structured Streaming MLlib (DataFrame-based) Spark Streaming MLlib (RDD-based) Spark Core Resource Management pyspark.sql.Column.cast¶ Column.cast(dataType)[source]¶ Convert the column into type dataType.
How to typecast Spark DataFrame columns? Using pyspark
stackoverflow.com › questions › 52871560Oct 18, 2018 · To change the datatype you can for example do a cast. For example, consider the iris dataset where SepalLengthCm is a column of type int. If you want to cast that int to a string, you can do the following: df.withColumn('SepalLengthCm',df['SepalLengthCm'].cast('string')) Of course, you can do the opposite from a string to an int, in your case. You can alternatively access to a column with a different syntax:
PySpark Documentation — PySpark 3.3.1 documentation
spark.apache.org › docs › latestPySpark is an interface for Apache Spark in Python. It not only allows you to write Spark applications using Python APIs, but also provides the PySpark shell for interactively analyzing your data in a distributed environment. PySpark supports most of Spark’s features such as Spark SQL, DataFrame, Streaming, MLlib (Machine Learning) and Spark Core.