python将object转换为float,如何在python中将datatype:object转换为float64?

从SQL导入的DataFrame中,某些原本为float64的数据被转换为Object,导致无法进行计算。通过使用`convert_objects`(已弃用)或`pd.to_numeric`方法,可以将Object类型的列转换回数值类型。例如,使用`str.replace`去除数字中的逗号和百分比符号,然后使用`astype`或`pd.to_numeric`进行转换。
摘要由CSDN通过智能技术生成

I am going around in circles and tried so many different ways so I guess my core understanding is wrong. I would be grateful for help in understanding my encoding/decoding issues.

I import the dataframe from SQL and it seems that some datatypes:float64 are converted to Object. Thus, I cannot do any calculation. I fail to convert the Object back to float64.

df.head()

Date WD Manpower 2nd CTR 2ndU T1   T2   T3   T4

2013/4/6 6 NaN 2,645 5.27% 0.29 407 533 454 368

2013/4/7 7 NaN 2,118 5.89% 0.31 257 659 583 369

2013/4/13 6 NaN 2,470 5.38% 0.29 354 531 473   383

2013/4/14 7 NaN 2,033 6.77% 0.37 396 748 681 458

2013/4/20 6 NaN 2,690 5.38% 0.29 361 528 541 381

df.dtypes

WD float64

Manpower float64

2nd object

CTR object

2ndU float64

T1 object

T2 object

T3 object</

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值