Pandas:将excel中字符型数据转为float数值型
使用Pandas读取excel中的数据时,常常会遇到类似1,000,000这样的数据。Pandas读取后会认为这是个字符型,而这样的数据还不能直接用类型转换实现。正确的用法如下:data['amount'] = data['amount'].apply(lambda x: float(x.split()[0].replace(',', ''))if(',' in str(...
·
使用Pandas读取excel中的数据时,常常会遇到类似1,000,000这样的数据。Pandas读取后会认为这是个字符型,而这样的数据还不能直接用类型转换实现。正确的用法如下:
data['amount'] = data['amount'].apply(
lambda x: float(x.split()[0].replace(',', ''))
if(',' in str(x)) else float(x))
)
更多推荐



所有评论(0)