如何更改多个特定列的数据类型

问题描述

当我还需要将,更改为时,如何将多列更改为浮点数。

DF 看起来像这样

enter image description here

除了我删除了所有 NAN 值,因为我不需要这些行。

这是数据类型

enter image description here

这就是我现在做的方式,但需要很长时间。我知道你可以做一个循环,但我不明白怎么做。

enter image description here

解决方法

使用df.iloc

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