I'm using numpy to retrieving data from csv file, it contains 3 columns with data: offer_id, sms_limit, sms_price. I want to add validation:
- offer_id - only positive integers
- sms_limit - only positive integers
- sms_price - positive float number.
I've tried to write my own validator, something like this:
def int_validator(x):
if str(x).isdigit():
return x
raise ValueError('Invalid choice please use positive integer number')
pd.read_csv(
converters={'offer_id': int_validator, 'sms_limit': int, 'sms_price': int},
encoding='utf-8',
engine='python',
)
but it doesn't work at all :(
It only works if I use int
pd.read_csv(
converters={'offer_id': int, 'sms_limit': int, 'sms_price': int},
encoding='utf-8',
engine='python',
)
but it's not what I'm looking for. Also, it's only working for column offer_id if I type a string into sms_limit or sms_price there is no validation. Can smb explain how to write my validators and why only the first column accepts int conversion?