Member-only story
Transform Rows into Columns in Kusto
Data pivoting in Kusto
The problem description
Before feeding the data to a machine learning model, I need to tidy the data as needed. For example, I have a table with user id and using services.
I need to dynamically transform the data using the used services as the column name. Assign value 1 to users using it. Making the services as ML training features.
In other words, what I am trying to do is rotate a table by turning the unique values from one column in the source table into multiple columns in the target table and performs exists checking as the boolean value that will appear as 1
or 0
in the final output.
A solution in Kusto
This transformation can be done in Kusto with just several lines of code, on million rows of data. Here are the steps to do it.
Prepare demo data in Kusto
let demo_data = datatable(
user_id:int…