I have a dataframe df with 2 columns price and max_price. I want have these validations:
- the values in
max_pricecolumn must be=> 0. - the values in
pricecolumn must be=> 0, but also be<= max_pricein the corresponding row.
I have the following code. I only know how to check => 0 for the price column, but don't know how to check if it is higher than the value in max_price column.
import pandas as pd
from pandas_schema import Column, Schema
from pandas_schema.validation import InRangeValidation
df = pd.DataFrame({'price': [1, 10, 20], 'max_price': [10, 5, 25]})
schema = Schema([
Column('price', [InRangeValidation(min=0)]), # how to check with the column `max_price`?
Column('max_price', [InRangeValidation(min=0)])
])
errors = schema.validate(df)
for error in errors:
print(error)
Here, the 2nd row in df is invalid, since the price is 10 while the max_price is just 5.
Could you please show me how to make the code correct? Thanks.