how to cast all columns of dataframe to string

前端 未结 3 583
没有蜡笔的小新
没有蜡笔的小新 2020-12-31 13:18

I have a mixed type dataframe. I am reading this dataframe from hive table using spark.sql(\'select a,b,c from table\') command.

Some columns are int

3条回答
  •  梦毁少年i
    2020-12-31 13:54

    Just:

    from pyspark.sql.functions import col
    
    table = spark.sql("table")
    
    table.select([col(c).cast("string") for c in table.columns])
    

提交回复
热议问题