How to convert column with string type to int form in pyspark data frame?

前端 未结 3 389
忘了有多久
忘了有多久 2020-12-24 05:33

I have dataframe in pyspark. Some of its numerical columns contain \'nan\' so when I am reading the data and checking for the schema of dataframe, those columns will have \'

3条回答
  •  一整个雨季
    2020-12-24 05:59

    from pyspark.sql.types import IntegerType
    data_df = data_df.withColumn("Plays", data_df["Plays"].cast(IntegerType()))
    data_df = data_df.withColumn("drafts", data_df["drafts"].cast(IntegerType()))
    

    You can run loop for each column but this is the simplest way to convert string column into integer.

提交回复
热议问题