从一列薪水python 3中删除$ [英] Remove $ from a column of salaries python 3
问题描述
我试图从我从 csv 文件中读取的工资列表中打印最小值和最大值,但首先我必须从值中删除 $ 并且不知道如何.
I am trying to print the min and max from a list of salaries that I am reading from a csv file, but first I must remove the $ from the value and don't know how.
我尝试遍历列表并使用 del[0]
并得到:
I tried iterating through the list and using del[0]
and got:
语法错误:无法删除文字.
SyntaxError: can't delete literal.
我尝试了 salary.replace("$", " ")
并得到:
AttributeError: 'list' 对象没有属性 'replace'
AttributeError: 'list' object has no attribute 'replace'
我将薪水列附加到一个不可变字符串的列表中.
I appended the salaries column to a list which is an immutable string.
如何从看起来像 [$98,500.85] 的工资表中删除 $?提前致谢.
How would I remove the $ from a salary list that looks like [$98,500.85]? Thanks in advance.
推荐答案
如果没有代码,很难知道确切的问题,但您可以尝试以下方法之一:
Hard to know the exact problem without the code, but you could try one of these:
new_salary = [s.replace("$", "") for s in salary]
或:
new_salary = [s[1:] for s in salary]
这篇关于从一列薪水python 3中删除$的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!