title: How can I tidy (melt) data in Pandas and keep all other columns?
body: <p>Consider this Pandas dataframe:</p>
  
  <pre><code>df = pd.DataFrame({
      'User ID': [1, 2, 2, 3],
      'Cupcakes': [1, 5, 4, 2],
      'Biscuits': [2, 5, 3, 3],
      'Score': [0.65, 0.12, 0.15, 0.9]
  })
  </code></pre>
  
  <p>ie.</p>
  
  <pre><code>   User ID  Cupcakes  Biscuits  Score
  0        1         1         2   0.65
  1        2         5         5   0.12
  2        2         4         3   0.15
  3        3         2         3   0.90
  </code></pre>
  
  <p>I want to <a href="http://vita.had.co.nz/papers/tidy-data.pdf" rel="noreferrer">tidy ("melt")</a> this data so that the dessert <em>type</em> are separate observations. But I also want to keep the score for each user.</p>
  
  <p>Using <a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.melt.html" rel="noreferrer"><code>melt()</code></a> directly doesn't work:</p>
  
  <pre><code>df.melt(
      id_vars=['User ID'],
      value_vars=['Cupcakes', 'Biscuits'],
      var_name='Dessert', value_name='Enjoyment'
  )
  </code></pre>
  
  <p>...gives:</p>
  
  <pre><code>   User ID   Dessert  Enjoyment
  0        1  Cupcakes          1
  1        2  Cupcakes          5
  2        2  Cupcakes          4
  3        3  Cupcakes          2
  4        1  Biscuits          2
  5        2  Biscuits          5
  6        2  Biscuits          3
  7        3  Biscuits          3
  </code></pre>
  
  <p>I've lost the score data!</p>
  
  <p>I can't use <a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.wide_to_long.html?highlight=wide_to_long#pandas.wide_to_long" rel="noreferrer"><code>wide_to_long()</code></a> because I don't have a common "stub name" for my dessert types.</p>
  
  <p>I can't join or merge the tidied data with the original data because the tidied data is reindexed and the user ID is not unique for each observation.</p>
  
  <p>How do I tidy this data but retain columns that aren't involved in the tidying?</p>