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

前端 未结 3 388
忘了有多久
忘了有多久 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-24 05:54

    You could use cast(as int) after replacing NaN with 0,

    data_df = df.withColumn("Plays", df.call_time.cast('float'))
    

提交回复
热议问题