title: Pandas Error: Index contains duplicate entries, cannot reshape
body: <p>My question seems duplicate as I found different questions with the same error as follows:</p>
  <blockquote>
  <p><a href="https://stackoverflow.com/questions/44847747/pandas-grouping-a-column-on-a-value-and-creating-new-column-headings">Pandas: grouping a column on a value and creating new column headings</a></p>
  <p><a href="https://stackoverflow.com/questions/45825381/python-pandas-valueerror-index-contains-duplicate-entries-cannot-reshape">Python/Pandas - ValueError: Index contains duplicate entries, cannot reshape</a></p>
  <p><a href="https://stackoverflow.com/questions/46528599/pandas-pivot-produces-valueerror-index-contains-duplicate-entries-cannot-resh">Pandas pivot produces &quot;ValueError: Index contains duplicate entries, cannot reshape</a></p>
  </blockquote>
  <p>I tried all the solutions presented on those posts, but none worked. I believe the error maybe be caused by my dataset format, which has Strings instead of numbers and possible duplicate entires. Here follows an example of my Dataset:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>protocol_no</th>
  <th>activity</th>
  <th>description</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1586212</td>
  <td>walk</td>
  <td>twice a day</td>
  </tr>
  <tr>
  <td>1586212</td>
  <td>drive</td>
  <td>5 km</td>
  </tr>
  <tr>
  <td>1586212</td>
  <td>drive</td>
  <td>At least 30 min</td>
  </tr>
  <tr>
  <td>1586212</td>
  <td>sleep</td>
  <td>NaN</td>
  </tr>
  <tr>
  <td>1586212</td>
  <td>eat</td>
  <td>1500 calories</td>
  </tr>
  <tr>
  <td>2547852</td>
  <td>walk</td>
  <td>NaN</td>
  </tr>
  <tr>
  <td>2547852</td>
  <td>drive</td>
  <td>NaN</td>
  </tr>
  <tr>
  <td>2547852</td>
  <td>eat</td>
  <td>3200 calories</td>
  </tr>
  <tr>
  <td>2547852</td>
  <td>eat</td>
  <td>Avoid pasta</td>
  </tr>
  <tr>
  <td>2547852</td>
  <td>sleep</td>
  <td>At least 10 hours</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>The output I'm trying to achieve is:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>protocol_no</th>
  <th>walk</th>
  <th>drive</th>
  <th>sleep</th>
  <th>eat</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1586212</td>
  <td>twice a day</td>
  <td>5km</td>
  <td>NaN</td>
  <td>1500 calories</td>
  </tr>
  <tr>
  <td>2547852</td>
  <td>NaN</td>
  <td>NaN</td>
  <td>3200 calories</td>
  <td>At least 10 hours</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I tried using pivot and pivot_table with a code like this:</p>
  <pre><code>df.pivot(index=&quot;protocol_no&quot;, columns=&quot;activity&quot;, values=&quot;description&quot;)
  </code></pre>
  <p>But I'm still getting this error:</p>
  <pre><code>ValueError: Index contains duplicate entries, cannot reshape
  </code></pre>
  <p>Have no idea what is going wrong, so any help will be helpful!</p>
  <p><strong>EDIT:</strong></p>
  <p>I noticed my data contains duplicate entires as stated by the error and by @DYZ and @SeaBean users. So I've edited the database example and provided the correct answer for my dataset as well. Hope it helps someone.</p>