Member-only story

Transform Rows into Columns in Kusto

Data pivoting in Kusto

Andrew Zhu
4 min readNov 25, 2022

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

--

--

Andrew Zhu
Andrew Zhu

Written by Andrew Zhu

Working on AI stuffs | a HF Diffusers contributor | a ex-Data Scientist@MS | His LinkedIn is www.linkedin.com/in/andrew-zhu-23407223/

Responses (1)