2

I have the following table :

user      category    number
1         A           8
1         B           6
2         A           1
2         C           9
3         B           5

I want to "unfold" or "dummify" the category column and fill them with the "number" column to obtain:

user      cat_A    cat_B    cat_C
1         8        6        0
2         1        0        9
3         0        5        0

Is it possible to achieve this in SQL (Impala) ?

I found this question How to create dummy variable columns for thousands of categories in Google BigQuery?

However it seems a little bit complex and I'd rather do it in Pandas.

Is there a simpler solution, knowing that I have 10 categories (A, B, C, D etc)?

4

1 に答える 1