title: Can I move specific column names in my pandas DataFrame to rows?
body: <p>Initial DataFrame</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>machine</th>
  <th>attribute_1</th>
  <th>attribute_2</th>
  <th>attribute_3</th>
  <th>part</th>
  <th>date</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>D1</td>
  <td>1</td>
  <td>2.1</td>
  <td>3.5</td>
  <td>G1</td>
  <td>2022-07-13</td>
  </tr>
  <tr>
  <td>D1</td>
  <td>1.3</td>
  <td>23.4</td>
  <td>13.1</td>
  <td>G1</td>
  <td>2022-07-13</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Pivoted DataFrame</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>machine</th>
  <th>attribute</th>
  <th>value</th>
  <th>part</th>
  <th>date</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>D1</td>
  <td>attribute_1</td>
  <td>1.1</td>
  <td>G1</td>
  <td>2022-07-13</td>
  </tr>
  <tr>
  <td>D1</td>
  <td>attribute_1</td>
  <td>1.3</td>
  <td>G1</td>
  <td>2022-07-13</td>
  </tr>
  <tr>
  <td>D1</td>
  <td>attribute_2</td>
  <td>2.1</td>
  <td>G1</td>
  <td>2022-07-13</td>
  </tr>
  <tr>
  <td>D1</td>
  <td>attribute_2</td>
  <td>23.4</td>
  <td>G1</td>
  <td>2022-07-13</td>
  </tr>
  <tr>
  <td>D1</td>
  <td>attribute_3</td>
  <td>3.5</td>
  <td>G1</td>
  <td>2022-07-13</td>
  </tr>
  <tr>
  <td>D1</td>
  <td>attribute_3</td>
  <td>13.1</td>
  <td>G1</td>
  <td>2022-07-13</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I can do this with a nested for loop, but the initial dataframe is already 3000 rows with 11 attributes. My for loop takes about 2 minutes to run, and that is way too slow for what I'm trying to do. Is there a faster way to do this?</p>
  <p>Edit:</p>
  <p>This question was answered <a href="https://stackoverflow.com/questions/68961796/how-do-i-melt-a-pandas-dataframe">here</a>. I was able to melt the table using the below code.</p>
  <pre><code>df.melt(id_vars=['machine','part','date'], var_name='attribute', value_name='value')
  </code></pre>