How to use Scikit Learn dictvectorizer to get encoded dataframe from dense dataframe in Python?
<p>I have a dataframe as follows:</p>

<pre><code>   user  item  affinity
0     1    13       0.1
1     2    11       0.4
2     3    14       0.9
3     4    12       1.0
</code></pre>

<p>From this I want to create an encoded dataset (for <code>fastFM</code>) as follows:</p>

<pre><code>  user1 user2 user4 user4 item11 item12 item13 item14 affinity
    1     0     0     0     0      0      1      0       0.1
    0     1     0     0     1      0      0      0       0.4
    0     0     1     0     0      0      0      1       0.9
    0     0     0     1     0      1      0      0       1.0
</code></pre>

<p>Do I need a <code>dictvectorizer</code> from <code>sklearn</code>? If yes, then is there a way to convert original dataframe to dictionary which can be given to <code>dictvectorizer</code> which will in turn give me the encoded dataset as shown?</p>