0

i want to build a collaborative user-base model and i have 20 users and 2234 items i have table of 20 users that rated 2234 movies (most users didn't rate not all of them). i have this sort of table :

 userId   movieId  Rating
    1       123      3.5
    1       36       2.2
    1       42       4.1
    2        .       3.1
    2        .        .
    3        .        .
    .        .        .
    .        .        .
    20       .        .

and I want to become like this :

enter image description here

i want to became a matric that have 20 user row and 2234 columns and the value is rating.

How can i do it ?

Hossein
  • 11
  • 1
  • 7
  • Does this answer your question? [How can I pivot a dataframe?](https://stackoverflow.com/questions/47152691/how-can-i-pivot-a-dataframe) – Chris Jul 06 '22 at 16:34

1 Answers1

0

Try this

df.unstack('movieId')

This action shall move the row based indexes and formulate column indexes. Giving you the wanted result, Chris commentary also is a good sugestion. To your issue.

INGl0R1AM0R1
  • 1,532
  • 5
  • 16