Skip to content

API: read_excel: on header and index_col #34766

Description

@kuraga

Good day!

read_excel's header and index_col handling rules I see:

  • in all cases of header:
    • cells (header, outside of index_col) are used as df.columns.
  • if header is a integer/one-item list:
    • df.columns.name is untouched,
    • cells (greater than max(header), index_col) are used for df.index,
    • cells (header, index_col) are used for df.index.name.
  • else (i.e., header is a (2-up-items) list):
    • according to BUG: read_excel issue - 3 (header is a list, index_col is not range(N)) #34765, index_col should be None or 0 or range(0, max_index_col+1, 1).
    • if row max(header)+1 is empty except columns index_col:
      • cells (greater than max(header)+1, index_col) are used for df.index,
      • cells (max(header)+1, index_col) are used for df.index.names,
    • else:
      • cells (greater than max(header), index_col) are used for df.index,
      • df.index.names is not set.
      • cells (header, max(index_col)) are used for df.columns.names.
      • non-max columns of index_col aren't used for df.index/df.columns.

Other observations:

  • rows above min(header) are omitted.
  • header is 0-based or skiprows-1-based?

So,

  1. Isn't it too complicated, is it?
  2. Is each this rule is documented?
  3. Is each this rule is tested?

demo_suite.zip

Any thoughts? Thanks!

/cc @TomAugspurger @jreback

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions