首页 > 解决方案 > 使用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'])

标签: python-2.7

解决方案


你可以试试 :

用空字符串替换$

 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'])

推荐阅读