To preserve merged cells when converting an HTML table to another HTML format, retain the original <th> and <td> elements and their rowspan and colspan attributes. If the destination is a rectangular grid or DataFrame, expand each cell across the rows and columns it occupies—and keep the original span metadata if you may need to rebuild the merged layout.
What colspan and rowspan preserve
colspan specifies how many columns a cell occupies; rowspan specifies how many rows it occupies. Both default to one. These attributes describe the table’s structure, not just its displayed text: a spanning cell reserves positions, so later cells in the same row or subsequent rows move to the next available position. Counting cell tags in each row therefore does not reliably reveal the table’s logical columns.
The W3C’s HTML 4.01 table specification also assigns special meanings to a span value of zero in the context of row or column groups. Its examples show how spanning cells affect placement, and warn: “Defining overlapping cells is an error. User agents may vary in how they handle this error (e.g., rendering may vary).” If spans conflict, do not silently repair the table and present the result as definitive; flag the issue or document an explicit handling policy.
Choose the output you need
There are two different goals: retaining the source’s merged-cell structure, or representing its contents as a rectangular grid. A grid records values by row and column; the original span attributes record which source cell covered those positions. Choose before transforming the table.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
| Approach | Preserves merged-cell structure | Produces rectangular values | Main tradeoff |
|---|---|---|---|
| Transform the HTML DOM and retain span attributes | Yes, if the transformation keeps the original cells and attributes | No, unless you expand it separately | Best when HTML structure is the deliverable |
| Expand cells into a grid and keep source mapping | Can be reconstructed if mapping and span metadata are retained | Yes | Requires a rule for covered positions and malformed spans |
pandas.read_html |
No source-markup round trip is promised | Yes | Convenient extraction, but cleanup and validation may be needed |
This is a comparison of output behavior, not a benchmark.
Keep the spans when the result is still HTML
- Parse the document into a tree and select the intended table.
- Make changes to the retained cells rather than replacing a spanning cell with multiple independent cells.
- Serialize the table and verify that each original
rowspanandcolspanremains on the correct<th>or<td>.
Beautiful Soup supports modifying and writing a parsed tree. The important preservation step is to avoid deleting or overwriting the span attributes during your transformation. An expanded grid by itself is not enough to recover which positions originated in a single merged cell.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
Expand spans for a rectangular grid
To create a matrix or DataFrame, track which row-and-column coordinates are already occupied. For each source cell, find the next unoccupied position in its row, read its span values (using one when an attribute is absent), and mark the rectangle it covers. Place the cell’s value at its anchor coordinate.
- Maintain an occupancy map for the rows and columns being converted.
- For each cell, skip columns already occupied by cells spanning from an earlier position or row.
- Read
rowspanandcolspan, applying the HTML defaults when the attributes are absent. - Mark every coordinate covered by that rectangle before placing the next cell.
- Choose whether covered positions repeat the anchor value or remain blank. Record that choice because the two layouts mean different things to downstream consumers.
- Keep each source cell’s anchor and span dimensions if the grid may later need to be converted back to merged HTML.
This placement rule follows the specification’s occupancy model and is reflected in pandas’ implementation. Do not assume that repeating a value or leaving covered positions blank is universally correct; select the representation that fits the consumer of the grid.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsRank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
Use pandas for extraction, then inspect the result
pandas.read_html searches for tables and returns a list of DataFrames. Its documentation says it attempts to handle colspan and rowspan, while noting that cleanup may still be needed. See the pandas.read_html API reference. Inspect the returned DataFrame for your particular input rather than assuming headers, blank cells, or irregular markup have mapped to the intended schema.
In the development API documentation accessed on October 4, 2026, read_html supports lxml, html5lib, and Beautiful Soup. Without a selected flavor, it tries lxml and falls back to Beautiful Soup plus html5lib if that parse fails. Development documentation may change, so check the documentation and behavior for the pandas release you actually deploy.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Make parsing reproducible
Malformed markup can produce different parse trees depending on the parser. Beautiful Soup documents this difference and supports multiple parser backends. When consistent results matter, specify the parser explicitly, especially for jobs running on multiple machines. For conversions that must be audited, record relevant library versions alongside the output.
Validate the converted table
- Compare the output’s row and column occupancy with the intended source layout.
- Check that a row-spanning cell blocks its column in later rows before another cell is placed there.
- Check that a column-spanning cell reserves all of its columns before subsequent cells are placed in the same row.
- Inspect
<thead>,<tbody>, and<tfoot>separately. Pandas’ implementation expands these sections and carries remaining rowspan state across them. - Flag spans that overlap other cells or exceed the available structure instead of silently claiming an exact conversion.
- If the output must return to HTML, confirm that the original span attributes remain attached to their source cells; a grid alone does not preserve merged-cell provenance.
For the last check, the distinction between source attributes and expanded grid values is an implementation inference from the HTML occupancy model and pandas’ expanded output behavior, not a promise of automatic round-trip reconstruction.
Recommended Free Tools
Quick Recap
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

