I have a pandas DataFrame of shape (350000, 910). All of the 910 columns have type object and small values like e.g. 1.0 or 2.0. I want them as type float64.
This seemed not to be a difficult problem at all. However, once trying out different solutions like
df[all_cols] = df[all_cols].astype('float64') # or
df[all_cols] = df[all_cols].astype(np.float64)
I found that it takes 1 hour for not even 10% of the total number of columns.
Is there any way I can make this calculation significantly faster?
Example code:
import string
import pandas as pd
import numpy as np
all_cols = [letter + str(x) for x in range(1, 36) for letter in string.ascii_uppercase]
df = pd.DataFrame(np.random.randint(0, 5, size=(300_000, len(all_cols))), columns=all_cols)