Код: Выделить всё
import pandas as pd
import pandera as pa
schema = pa.DataFrameSchema({
'Invoice Type': pa.Column(str, pa.Check(lambda s: s.isin(['Invoice', 'Credit']))),
'Quantity': pa.Column(
int,
checks=[
pa.Check(
lambda df: df[True] < 0,
groupby=lambda df: (
df.assign(is_credit=lambda d: d["Invoice Type"] == 'Credit').groupby(['is_credit'])
),
name = 'negative credits quantities'),
pa.Check(
lambda df: df[True] >= 0,
groupby=lambda df: (
df.assign(is_invoice=lambda d: d['Invoice Type'] == 'Invoice').groupby(['is_invoice'])
),
name = 'postitive invoices quantities'),
]),
'Customer Number': pa.Column(str)
})
df = pandas.DataFrame(
{'Quantity': [1, 2, -3],
'Invoice Type': ['Invoice', 'Invoice', 'Credit'],
'Customer Number': ['ABC', 'ABC', 'DEF']}
)
Код: Выделить всё
df = pandas.DataFrame(
{'Quantity': [1, 2, 3],
'Invoice Type': ['Invoice', 'Invoice', 'Invoice'],
'Customer Number': ['ABC', 'ABC', 'DEF']}
)
Подробнее здесь: https://stackoverflow.com/questions/785 ... -may-or-ma