python - 如何将₹22000字符串转换为python中的浮点数
问题描述
回溯(最近一次调用):文件“scrap.py”,第 13 行,在 convert_price=float(price[:5]) 中 ValueError:无法将字符串转换为浮点数:'₹\xa022,'
解决方案
你可以使用
dirty = "₹22000.83"
try:
cleaned = float("".join(char for char in dirty if
char in ["-", "."] or char.isdigit()))
print(cleaned)
except ValueError:
pass
哪个产量
22000.83
推荐阅读
- bluetooth-lowenergy - How to link USR-7S4 with TI CC2640R2F through UART programming?
- terminal - The custom module does not appear in the 'list of app' in odoo13?
- django - How to use django-autocomplete-light on django-countries==7.1 country fields for admin panel
- wordpress - How to remove unused CSS/JS and Improve server response time for WordPress website?
- css - How can i center the content of my footer?
- dns - How to run forms exe on all domain accounts at logon
- python - 如何使用 M1 在 MacOS 上安装 h5py(Keras 需要)?
- android - 退出应用程序后。计时器结束计数后如何打开下一个活动?
- python - Beautifulsoup:提取表中的 td 列表
- python - 如何从列中拆分数据并从数据框添加到列表中,还为单行重复列表元素?(熊猫)