'dummy variable encoding or one-hot encoding from Monday to Friday based on datetime with DolphinDB

Monday to Friday are independent variables of the model, but in order to eliminate the effects of 1-5 base units, one-hot encoding or dummy variables need to be constructed. enter image description here



Solution 1:[1]

Through the dayOfWeek(), you can get what day of the week the current date is, and then judged by iif, you can construct a 5-column sparse matrix (one-hot encoding)

for(i in 1:6)
{
outputTable["DW"+i] = iif(outputTable.interval_date_time.dayOfWeek()==i,1,0)
}

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 damie