title: Transforming a dataframe in Python
body: <p>I am trying to transform a pandas dataframe into a new format.</p>
  <p>I had two dataframes that I merged. The new dataframe contains duplicate entries and I want to transform it so that each of these duplicate entries is in a single row with extra columns that contain data of this duplication. I tried to use .pivot, .pivot_table, .melt, .unstack, but was unsuccessful to achieve what I want.</p>
  <p>Assuming that I have dataframe d1:</p>
  <pre class="lang-py prettyprint-override"><code>d1 = pd.DataFrame({&quot;Wall ID&quot;: [&quot;E12&quot;, &quot;E12&quot;, &quot;E12&quot;, &quot;C35&quot;, &quot;C35&quot;, &quot;C35&quot;],
                    &quot;Length&quot;: [15, 15, 15, 21, 21, 21],
                    &quot;Station&quot;: [&quot;A1&quot;, &quot;A2&quot;, &quot;A3&quot;, &quot;A1&quot;, &quot;A2&quot;, &quot;A3&quot;],
                    &quot;Time&quot;: [20, 14, 26, 29, 14, 12]})
  d1
  </code></pre>
  <p><a href="https://i.stack.imgur.com/oDayT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oDayT.png" alt="enter image description here" /></a></p>
  <p>I want to change it to dataframe d2:</p>
  <pre class="lang-py prettyprint-override"><code>d2 = pd.DataFrame({&quot;Wall ID&quot;: [&quot;E12&quot;, &quot;C35&quot;],
                    &quot;Length&quot;: [15, 21],
                    &quot;A1&quot;: [20, 29],
                    &quot;A2&quot;: [14, 14],
                    &quot;A3&quot;: [26, 12]})
  d2
  </code></pre>
  <p><a href="https://i.stack.imgur.com/o2wZQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/o2wZQ.png" alt="enter image description here" /></a></p>
  <p>Note that &quot;Length&quot; is always the same for the same &quot;Wall ID&quot;.</p>