Styxis
Company
Knowledge

pandas CSV and Excel MultiIndex headers: preserving the meaning of each level

Even when the value array matches, column-level names explain the axes to readers and require a separate agreement.

pandas CSV and Excel MultiIndex headers: preserving the meaning of each level

Equal values and column tuples in a multi-header table do not establish equal axis meaning if the level names change. Comparing readers only by matrix shape can miss that difference. A separate handover of the document author's level definitions supports acceptance of both values and axis descriptions. [1, 2, 3]

What the primary source establishes

A report compares CSV and Excel readers using multiple header rows and index columns. Their actual column tuples agree, but columns.names differ because the readers select different upper cells as level names. [1]

The handover decision

The document author should identify the meaning of each header row. The conversion owner should hand over level names and actual column tuples separately. Record header_level, approved_level_name, and parsed_level_name so that a matching matrix shape does not conceal a different explanation of the axes. [1, 3]

A reference defined before the output

In the illustrative contract, the first level means metric and the next means region. Assigning metric to the first level is normal; assigning region there fails the agreed meaning. A name should not be selected solely because it happens to occupy a convenient source cell. [1, 3]

The scoped Truthound check

Truthound Core 3.3.2 can compare approved_level_name and parsed_level_name by level position using ColumnPairValidator. Preserve both the actual column tuples and their level names. This comparison does not automatically decide which parser is universally correct. [1, 2, 3]

Limits and alternative choices

The report cannot establish that either the CSV or Excel path is correct for every file. Declare level names in a separate schema and apply that schema explicitly after import. If the consumer contracts only on fixed positions and never uses level names, the immediate impact differs, although the discrepancy can still be recorded. [1, 3]

Application conditions

Prepare approved and parsed level names by header-level identity, retaining the underlying column tuples.

Alternatives

Declare level names in a separate schema and apply that schema explicitly after import.

Limitations

  • The report cannot establish that either the CSV or Excel path is correct for every file.

Evidence

Event checked
Subject checked
Modified