python-2.7 - 使用python2进行数据清洗
问题描述
在我的代码中,我需要删除$
符号 usingdef
并且需要将它们转换numbers
为使用计算。
def remove_dollar(s):
"""Removes dollar signs and spaces from s.
Returns it as a float.
"""
# YOUR CODE HERE
s = sales(s)
s.remove('$')
return ''.join(s)
remove_dollar(sales['LastSpend'])
解决方案
你可以试试 :
用空字符串替换$
。
s = s.replace('$',"")
功能齐全:
def remove_dollar(s):
"""Removes dollar signs and spaces from s.
Returns it as a float.
"""
# YOUR CODE HERE
s = sales(s)
s = s.replace('$',"")
return s
remove_dollar(sales['LastSpend'])
推荐阅读
- oracle - 如何使用 Shell 脚本连接到用户定义的 Oracle 数据库?
- python - 尝试运行 LogisticRegression 的拟合函数时没有得到任何输出
- c++ - 使用基于范围的 for 循环遍历指针列表
- c# - .net ASP.NET 框架中的 Apple ID 身份验证不受支持的授予类型错误
- java - Spring Security OAuth2 自定义成功用户
- asp.net - 如何在 .NET 中创建货币转换器?
- python - 按下非ASCII字符时,pysimplegui键盘事件返回问号
- php - php无法获取网页的url内容
- html - 使用 CSS 设置 img 大小由填充宽度或高度确定。保持长宽比例
- swift - 在 Xcode 中,我可以使用 firebase 上传我的 Swift 应用程序,但我无法将数据从 firestore 导入我的应用程序。解决办法是什么?