title: Long to wide format for multiple column in python
body: <p>I am having a student examination dataset such as follows,</p>
  
  <pre><code>userid      grade   examid  subject     numberofcorrectanswers  numberofwronganswers
  4           5       8       Synonyms            NULL                    NULL
  4           5       8       Sentence            NULL                    NULL
  4           5       8       Whole Numbers       6                       15
  4           5       8       Decimals            4                       10
  5           5       9       Synonyms            NULL                    NULL
  5           5       9       Sentence            NULL                    NULL
  5           5       9       Whole Numbers       5                       12
  5           5       9       Decimals            3                       1
  </code></pre>
  
  <p>I want to convert this long format to wide format, where I can have the data as,</p>
  
  <pre><code>userid      grade   examid      Synonyms_numberofcorrectanswers         Synonyms_numberofwronganswers       Sentence_numberofcorrectanswers         Sentence_numberofwronganswers       Whole_numbers_numberofcorrectanswers        Whole_numbers_numberofwronganswers              Decimals_numberofcorrectanswers         Decimals_numberofwronganswers
  4           5           8               NULL                                    NULL                                NULL                                    NULL                                6                                           15                                          4                                           10
  5           5           9               NULL                                    NULL                                NULL                                    NULL                                5                                           12                                          3                                            1
  </code></pre>
  
  <p>The following are my trying,</p>
  
  <pre><code>data_subset.set_index(['userid', 'grade','examid','subject']).unstack('subject').reset_index()
  </code></pre>
  
  <p>But this is not coming in a single flat dataframe. There are several hierarchies inside it. Can anybody help me in making it a single flat dataframe?</p>
  
  <p>Thanks</p>