Looking to validate the data in a csv file using Python and Pandas. Everything works fine when feeding clean data. However when there is a problem with the data, the issues are hard to find. Raising any sort of error would be great. Here is some pseudo code:
dtypes = {'Date': 'str', 'yesno': 'str', 'int_val': 'int', 'decimal_value': 'str'}
df = pd.read_csv(filename, dtype=dtypes)
# Ensure exceptions are thrown for invalid data.
# valid date format in date. ValueError raised for invalid data.
pd.to_datetime(df['Date'])
# 'yes' or 'no' for the yesno field. (has to be in a list of values)
# valid integer for int_val.
# a valid integer or decimal number for decimal_value
I am not even sure the pd.to_datetime is the best way to validate a date. What is a good way of doing this?