title: How to flatten multiple column and rows in dataframe?
body: <p>Here's my excel data:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Main Topic</th>
  <th></th>
  <th></th>
  <th></th>
  <th></th>
  <th></th>
  <th></th>
  <th></th>
  <th></th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>Sr No</td>
  <td>column 1</td>
  <td></td>
  <td></td>
  <td></td>
  <td>column 2</td>
  <td></td>
  <td></td>
  <td></td>
  </tr>
  <tr>
  <td>Sr No</td>
  <td>sub-col1</td>
  <td>sub-col2</td>
  <td>sub-col3</td>
  <td>sub-col4</td>
  <td>sub-col1</td>
  <td>sub-col2</td>
  <td>sub-col3</td>
  <td>sub-col4</td>
  </tr>
  <tr>
  <td>First Topic</td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  </tr>
  <tr>
  <td>1) Sub Topic-1</td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  </tr>
  <tr>
  <td>1</td>
  <td>107</td>
  <td>207</td>
  <td>307</td>
  <td>407</td>
  <td>507</td>
  <td>607</td>
  <td>707</td>
  <td>807</td>
  </tr>
  <tr>
  <td>2</td>
  <td>108</td>
  <td>208</td>
  <td>308</td>
  <td>408</td>
  <td>508</td>
  <td>608</td>
  <td>708</td>
  <td>808</td>
  </tr>
  <tr>
  <td>3</td>
  <td>109</td>
  <td>209</td>
  <td>309</td>
  <td>409</td>
  <td>509</td>
  <td>609</td>
  <td>709</td>
  <td>809</td>
  </tr>
  <tr>
  <td>4</td>
  <td>110</td>
  <td>210</td>
  <td>310</td>
  <td>410</td>
  <td>510</td>
  <td>610</td>
  <td>710</td>
  <td>810</td>
  </tr>
  <tr>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  </tr>
  <tr>
  <td>2) Sub Topic-2</td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  </tr>
  <tr>
  <td>1</td>
  <td>113</td>
  <td>213</td>
  <td>313</td>
  <td>413</td>
  <td>513</td>
  <td>613</td>
  <td>713</td>
  <td>813</td>
  </tr>
  <tr>
  <td>2</td>
  <td>114</td>
  <td>214</td>
  <td>314</td>
  <td>414</td>
  <td>514</td>
  <td>614</td>
  <td>714</td>
  <td>814</td>
  </tr>
  <tr>
  <td>3</td>
  <td>115</td>
  <td>215</td>
  <td>315</td>
  <td>415</td>
  <td>515</td>
  <td>615</td>
  <td>715</td>
  <td>815</td>
  </tr>
  <tr>
  <td>4</td>
  <td>116</td>
  <td>216</td>
  <td>316</td>
  <td>416</td>
  <td>516</td>
  <td>616</td>
  <td>716</td>
  <td>816</td>
  </tr>
  <tr>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  </tr>
  <tr>
  <td>Second Topic</td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  </tr>
  <tr>
  <td>1) Sub Topic-1</td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  </tr>
  <tr>
  <td>1</td>
  <td>120</td>
  <td>220</td>
  <td>320</td>
  <td>420</td>
  <td>520</td>
  <td>620</td>
  <td>720</td>
  <td>820</td>
  </tr>
  <tr>
  <td>2</td>
  <td>121</td>
  <td>221</td>
  <td>321</td>
  <td>421</td>
  <td>521</td>
  <td>621</td>
  <td>721</td>
  <td>821</td>
  </tr>
  <tr>
  <td>3</td>
  <td>122</td>
  <td>222</td>
  <td>322</td>
  <td>422</td>
  <td>522</td>
  <td>622</td>
  <td>722</td>
  <td>822</td>
  </tr>
  <tr>
  <td>4</td>
  <td>123</td>
  <td>223</td>
  <td>323</td>
  <td>423</td>
  <td>523</td>
  <td>623</td>
  <td>723</td>
  <td>823</td>
  </tr>
  <tr>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  </tr>
  <tr>
  <td>2) Sub Topic-2</td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  <td></td>
  </tr>
  <tr>
  <td>1</td>
  <td>126</td>
  <td>226</td>
  <td>326</td>
  <td>426</td>
  <td>526</td>
  <td>626</td>
  <td>726</td>
  <td>826</td>
  </tr>
  <tr>
  <td>2</td>
  <td>127</td>
  <td>227</td>
  <td>327</td>
  <td>427</td>
  <td>527</td>
  <td>627</td>
  <td>727</td>
  <td>827</td>
  </tr>
  <tr>
  <td>3</td>
  <td>128</td>
  <td>228</td>
  <td>328</td>
  <td>428</td>
  <td>528</td>
  <td>628</td>
  <td>728</td>
  <td>828</td>
  </tr>
  <tr>
  <td>4</td>
  <td>129</td>
  <td>229</td>
  <td>329</td>
  <td>429</td>
  <td>529</td>
  <td>629</td>
  <td>729</td>
  <td>829</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p><strong>image1.png</strong></p>
  <p><a href="https://i.stack.imgur.com/H47Nn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/H47Nn.png" alt="enter image description here" /></a></p>
  <p>Now, I want to change the data (because my data modeling guy said to make it this way before adding to sql) and I don't know how to change it to such dataframe.</p>
  <p>The change is shown in below image:</p>
  <p><strong>image2.png</strong></p>
  <p><a href="https://i.stack.imgur.com/9NUrl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9NUrl.png" alt="enter image description here" /></a></p>
  <p>P.S. Note: This is dummy data and the length of rows and columns always vary. Any help me appreciated.</p>