String to integer
Now you'll use the .cast() method you learned in the previous exercise to convert all the appropriate columns from your DataFrame model_data to integers!
To convert the type of a column using the .cast() method, you can write code like this:
dataframe = dataframe.withColumn("col", dataframe.col.cast("new_type"))
Questo esercizio fa parte del corso
Foundations of PySpark
Istruzioni dell'esercizio
- Use the method
.withColumn()to.cast()the following columns to type"integer". Access the columns using thedf.colnotation:model_data.arr_delaymodel_data.air_timemodel_data.monthmodel_data.plane_year
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
# Cast the columns to integers
model_data = model_data.withColumn("arr_delay", ____)
model_data = model_data.withColumn("air_time", ____)
model_data = model_data.withColumn("month", ____)
model_data = model_data.withColumn("plane_year", ____)