I'm trying to convert an entire dataframe into integer, i.e. all Variables to type(int), the data has NaNs present, so was going for pd.to_numeric and coercing the errors to NaN, where I can handle them later.
But pd.to_numeric takes a list, tuple, 1-d array, or Series.
I can go on step by step by giving each column name and changing the type. But is there any way to do that optimally in few lines?
I tried this, but getting error.
change = lambda x: pd.to_numeric(df_copy[x], errors='coerce')
df_copy = pd.DataFrame(map(change, x) for x in df_copy.columns)