pythonpandasnumpyeda

How to change dtype of multiple specific columns


How do i change multiple columns to a float when i also need to change , to.

DF looks like this enter image description here except i dropped all the NAN values as i dont need those rows.

This is the dtypes enter image description here

And this is the way im doing it now, but it takes hella long time. I know you can do a loop but i don't understand how. enter image description here


Solution

  • Use df.iloc:

    df.iloc[:, 2:] = df.iloc[:, 2:].replace(',', '.', regex=True).astype(float)