0

I'm Trying to transform html tables with nested tables into a clean excel file.

Here is an example of what my table would look like:

[![html table](https://i.stack.imgur.com/5NoDC.png)](https://i.stack.imgur.com/5NoDC.png)

I want this to have the same structure in excel.

I tried using pandas but it doesn't seem to support nested tables. At some point I decided to give up on nested tables and just have multiple rows for each hosts looking a bit like this:

Pandas DataFrame

The problem is I would like to avoid repetitions in my DataFrame but more importantly I would have to check the difference in length of the lists of host_clients and host_addresses and it just doesn't seem clean to do.

Is there a way for me to have the same html table structure in an excel ? I've looked on many threads but I don't seem to find a solution that suits me or problem that suits mine.

Thanks in advance for any suggestions. InFeRnO_w

InFeRnO_w
  • 29
  • 4
  • 1
    pandas can handle [nested DataFrames](https://stackoverflow.com/a/51505854/6146136), but excel might have a harder time of it. See - if for a certain HOST, CLIENTS df has 3 rows (including header) and ADDRESS df has 5 row, excel would need a cell merged across ***15*** rows for that HOST, and 5 rows at a time merged for the clients and 3 at a time for address....doesn't it feel ike too much of a hassle? – Driftr95 Apr 07 '23 at 12:58
  • 1
    You *could* form a flat df by concatenating or joining the clients and addresses columns, with empty rows to pad whichever is shorter, but I think it would be better to have 2 different sheets for clients and addresses, with host column in both sheets [you can use host as level 1 of a multiIndex, and Excel, *does* retain merged/grouped index "cells" ] – Driftr95 Apr 07 '23 at 13:00
  • Hello Driftr95, thank you for ur quick response, I will try to see that solution – InFeRnO_w Apr 07 '23 at 13:05
  • Please provide enough code so others can better understand or reproduce the problem. – Community Apr 07 '23 at 14:21

0 Answers0