使用python2进行数据清理

时间:2019-05-21 06:05:55

标签: python-2.7

在我的代码中,我需要使用$删除def符号,并需要将它们转换为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'])

1 个答案:

答案 0 :(得分:0)

您可以尝试:

用空字符串替换$

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