Consider the following DataFrame:
df = pd.DataFrame({'a':['123','667','323'],
'b':['8000','1. 300', '56'],
'c':['11','apple', '100']})
# a b c
# 0 123 8000 11
# 1 667 1. 300 apple
# 2 323 56 100
I want to change the data type to int if it's a string of numbers. The regular expression is easy enough:
pattern = '^\d+$'
df.apply(lambda x: x.str.match(pattern, flags=re.IGNORECASE))
How to change the data type to int of any column that matches (column a in this example)? The column names are not consistent so I can't hard-code it. Do I need applymap here?