In my case, I had a df with mixed data:
df:
0 1 2 ... 242 243 244
0 2020-04-22T04:00:00Z 0 0 ... 3,094,409.5 13,220,425.7 5,449,201.1
1 2020-04-22T06:00:00Z 0 0 ... 3,716,941.5 8,452,012.9 6,541,599.9
....
The floats are actually objects, but I need them to be real floats.
To fix it, referencing @AMC's comment above:
def coerce_to_float(val):
try:
return float(val)
except ValueError:
return val
df = df.applymap(lambda x: coerce_to_float(x))