Skip to content

Multi-Level Column Headers #1027

Answered by cosmicBboy
aboomer07 asked this question in Q&A
Discussion options

You must be logged in to vote

love this library

❤️

You can use aliases in this case: https://pandera.readthedocs.io/en/stable/schema_models.html#aliases

import pandera as pa

class Schema(pa.SchemaModel):
    col1: pa.typing.Series[int] = pa.Field(alias=("level1", "col1"))
    col2: pa.typing.Series[int] = pa.Field(alias=("level1", "col2"), check_name=True)

print(Schema.to_schema())

output:

<Schema DataFrameSchema(
    columns={
        '('level1', 'col1')': <Schema Column(name=('level1', 'col1'), type=DataType(int64))>
        '('level1', 'col2')': <Schema Column(name=('level1', 'col2'), type=DataType(int64))>
    },
    checks=[],
    coerce=False,
    dtype=None,
    index=None,
    strict=False
    name=Schema,…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by cosmicBboy
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
enhancement New feature or request
2 participants
Converted from issue

This discussion was converted from issue #1025 on November 21, 2022 17:09.