In order to validate a column as hex values of a data frame I am doing something like this:
column = data_df[column_name]
try:
column.apply(lambda x: int(x, 16))
ok = True
except ValueError:
ok = False
The problem here seems to be the lambda
, since doing int(x, 16)
on the console works for any size of numbers.
I am getting an exception, since some values are too large:
In [1]: df.col.apply(lambda x: int(x, 16))
---------------------------------------------------------------------------
OverflowError Traceback (most recent call last)
...
OverflowError: Python int too large to convert to C unsigned long
What about performance doing this on large data? Can you think of a better solution?
I am new to python, so please be forgiving :) That was my source of inspiration: convert pandas dataframe column from hex string to int