Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To flatten merged HTML table cells safely, build a logical grid: place each cell in the next unoccupied column, then reserve every grid slot covered by its rowspan and colspan. Preserve the original cell’s coordinates and spans—or a coverage mask—so repeated values remain distinguishable from original cells. Simply reading cells in DOM order can shift values into the wrong columns.

Why merged cells need a grid

An HTML table is not just a sequence of cells. Each cell begins at a logical table coordinate and occupies a rectangular area. colspan sets how many columns the cell covers; rowspan sets how many rows it covers. The HTML Standard describes this as a table grid of slots, and MDN’s table basics guide explains the span attributes.

For example, if a cell starts in column 1 and has colspan="2", the next cell in that row belongs in column 3—not column 2. A cell with both spans reserves a rectangle across multiple rows and columns. A reliable transformation must account for that occupied area before placing later cells.

Choose what “flattened” should preserve

There are two common output goals. An analytical matrix often repeats a spanning cell’s value in every covered slot, making each row easier to process. A faithful representation instead keeps the value at its anchor and marks the other slots as covered. Repeating values alone loses the distinction between source cells and slots filled by a span.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • 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.

For data preservation, retain the original anchor coordinate, span dimensions, and whether each output slot is an anchor or covered. You can store that information alongside the matrix or emit cell records with fields such as value, source row, source column, rowspan, and colspan. If repeated values would alter the meaning of a table, use anchor-only values plus explicit coverage metadata.

Keep headers and their relationships too. For complex tables, MDN documents id and headers as a way to associate data cells with header cells; a flattened output may need equivalent header metadata or multi-level column labels. See MDN’s table element reference.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 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 into a logical grid

  1. Process rows in section order. Keep track of row groups such as thead, tbody, and tfoot. A span must respect the boundary of its row group.
  2. Find the next open slot. For each source cell in a row, move a column cursor forward past slots already occupied by cells spanning down from earlier rows.
  3. Read effective span values. Treat a missing rowspan or colspan as 1. Interpret rowspan="0" as extending through the remaining rows of the relevant row group, not as occupying zero rows.
  4. Place the anchor and reserve its rectangle. Record the source cell at its starting row and column, then mark every slot covered by its full rowspan-by-colspan area. Track anchors separately from covered slots.
  5. Continue across the row. Place each later source cell at the next unoccupied slot, taking all previously reserved rectangles into account.
  6. Normalize only after placement. Once all spans are mapped, determine the grid width. Preserve holes or inconsistent row widths as validation information rather than silently shifting cells.
  7. Emit the needed representation. Produce a rectangular value matrix, a matrix with an anchor/coverage mask, or records that retain source coordinates and spans.

This placement method follows the HTML Standard’s slot model. The provenance fields and mask are practical implementation choices to make the transformation easier to audit and less likely to lose information. The HTML Standard describes cell placement and coverage in the table grid.

Handle edge cases before trusting the output

  • Row and column spans together: reserve the entire rectangle before placing later cells, or those cells may land in the wrong logical column.
  • rowspan="0": extend the cell to the end of its row group. MDN discusses row-group boundaries and this special value in its td reference.
  • Missing, invalid, or extreme values: MDN documents default span values of 1 and clipping limits of 1000 for colspan and 65534 for rowspan. Parser and browser behavior may differ for malformed input, so validate what your parsing layer actually produced.
  • Multiple row groups: keep group boundaries explicit; do not carry a span into another section when the source semantics limit it to the current group.
  • Irregular tables: record warnings for overlaps, uncovered required slots, or inconsistent row widths instead of repairing them silently. The HTML Standard identifies uncovered slots as a table-model error in relevant cases.
  • Nested tables and non-text content: decide whether a cell’s value means plain text, links, markup, or a nested-table structure. Extracting only text can discard meaningful links or structure.
  • Headers: preserve <th> cells and header associations rather than treating every cell as interchangeable data.

Use pandas for ordinary extraction, then inspect

In Python, pandas.read_html searches HTML for tables and returns a list of DataFrames. The stable API documentation, which identifies pandas 3.0.6 in the documentation snapshot accessed October 4, 2026, says the function attempts to handle colspan and rowspan and warns that cleanup may be needed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • 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.

That makes it a convenient first choice for ordinary extraction when a DataFrame is the desired result. Inspect the returned frames for shifted columns, repeated span values, irregular rows, and header interpretation. If you need exact source coordinates, robust handling of malformed markup, or detailed header semantics, parse the HTML separately and retain the cell-level metadata alongside any DataFrame.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose a library or custom expander

Need Library-based parsing Custom grid expansion
Fast route to a DataFrame pandas.read_html returns DataFrames and attempts span handling; cleanup may be necessary. Requires building the grid logic and converting the result to a DataFrame if needed.
Source coordinates and span provenance Do not assume these are retained; inspect the output and parse separately if you need exact provenance. Can explicitly retain anchors, row/column coordinates, span sizes, and coverage markers.
Unusual or malformed markup Behavior depends on the parser and input; validate the result. Can expose overlaps, holes, and width inconsistencies, but you must define and implement those checks.
Header and row-group semantics Inspect whether the resulting labels preserve the relationships your use case needs. Can model row groups and header associations directly, at the cost of more implementation work.

Use the library route when convenience and a usable table are the priority. Choose a custom expander when auditability, provenance, or explicit validation is essential. Either way, check the output against the source table before relying on it downstream.

Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 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.
Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • 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

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.