pandera.api.dataframe.model_components.ParsedField¶
- pandera.api.dataframe.model_components.ParsedField(*, parser, source=None, on_error='raise', **field_kwargs)[source]¶
Declare a column derived from other columns of the same dataframe.
ParsedFieldisField()plus the provenance of the column’s values, so a model states where a column comes from instead of leaving it to a schema-levelparserslist:class Tickets(pa.DataFrameModel): body: str n_words: int = pa.ParsedField( source="body", parser=lambda s: s.str.split().str.len(), ge=1, )
- Parameters:
parser (
Any) – a callable producing the column’s values, or an object implementing theColumnParserprotocol. A callable receives the source column as aSerieswhen a single source is declared, and the selected source columns as aDataFrameotherwise.source (
Union[str,Iterable[str],None]) – the column(s) this column is derived from. Defaults to the model’sConfig.parser_source.on_error (
str) – what to do when the parser fails.
- Return type: