5

I want to turn column into a new rows and save the values.

For example:

BEFORE

NAME  COMDEDY  HORROR  ROMANCE
brian    10     20     14
tom      20     10     11

AFTER

NAME    GANRE    RATING
brian   comedy     10
brian   horror     20
brian   romance    14
tom     comedy     20
tom     horror     10
tom     romance    11

I need to do this at least with python pandas ,if I can't do it with prestodb

Gabio
  • 9,126
  • 3
  • 12
  • 32
nowheretogo
  • 125
  • 1
  • 5

1 Answers1

10

You can do it using presto sql:

SELECT t1.name, t2.genre, t2.rating
FROM table t1
CROSS JOIN unnest (
  array['comedy', 'horror', 'romance'],
  array[comedy, horror, romance]
) t2 (genre, rating)
Gabio
  • 9,126
  • 3
  • 12
  • 32