Skip to content

Print rows with invalid data type #654

Answered by jeffzi
Lavi2015 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @Lavi2015.

By default, pandera does not check values individually, but checks the dtypes of the columns (i.e. DataFrame.dtypes). To know the exact failure cases, you can enable coerce=True. Pandera will attempt to coerce the DataFrame to the schema dtypes and will report values that could not be coerced:

import pandas as pd
import pandera as pa

from pandera import Check, Column, DataFrameSchema

schema = pa.DataFrameSchema(
    columns={
        "int_column": Column(int),
        "float_column": Column(float),
        "str_column": Column(str),
    },
    strict=True,
    coerce=True, # <----
)

df = pd.DataFrame(
    {
        "int_column": ["a", 2, 3],
        "float_column": [0.0, 1.0

Replies: 4 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
Comment options

You must be logged in to vote
0 replies
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
question Further information is requested
2 participants
Converted from issue

This discussion was converted from issue #646 on October 13, 2021 12:45.