开发者社区> 问答> 正文

python中如何删除某一列中含有’万’字的数字,并将其替换为数字?

python中如何删除某一列中含有’万’字的数字,并将其替换为数字?

展开
收起
cuicuicuic 2021-12-03 22:20:23 848 0
1 条回答
写回答
取消 提交回答
  • test1 = test['bofang_num'] p = -1 for i in test['bofang_num']: p+=1 if i.find("万") !=-1: print(i) i = i.replace("万","") i = float(i)*10000 test['bofang_num'][p] = i print(i) Series可以通过索引值来访问数值!

    bool_index = test['bofang_num'].apply(lambda x:True if x.find("万")!=-1 else False) test.loc[bool_index,"bofang_num"] = test['bofang_num'][bool_index].apply(lambda x:float(x.replace("万",""))*1000)

    2021-12-03 22:20:39
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载