Quantcast
Channel: How can I change column types in Spark SQL's DataFrame? - Stack Overflow
Viewing all articles
Browse latest Browse all 24

Answer by Piyush Patel for How can I change column types in Spark SQL's DataFrame?

$
0
0

I think this is lot more readable for me.

import org.apache.spark.sql.types._df.withColumn("year", df("year").cast(IntegerType))

This will convert your year column to IntegerType with creating any temporary columns and dropping those columns.If you want to convert to any other datatype, you can check the types inside org.apache.spark.sql.types package.


Viewing all articles
Browse latest Browse all 24

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>