I am trying to turn some continuous variables into categorical variables in order to apply some ML algorithms to them and I want to make categories like from 6:00 to 12:00 --> "Morning" or dates in a format like ddMM to "Summer" or whatever.
These variables are already casted to integers. Like the recode
function in R, I think.
+----------+
|CRSDepTime|
+----------+
| 745|
| 1053|
| 1915|
| 1755|
| 832|
| 630|
| 820|
| 945|
| 1245|
| 1645|
| 620|
| 1125|
| 2045|
| 1340|
| 1540|
| 730|
| 1145|
| 525|
| 630|
| 1520|
+----------+
I solved this issue with this sentence!!
df = df.withColumn("Season", when(df("Month") >= 12 and df("Month") <=3, "Fall")
.when(df("Month") >= 4 and df("Month") <= 6, "Spring")
.when(df("Month") >= 7 and df("Month") <= 9, "Summer").otherwise("Autumm"))