我有一个包含以下条目的csv文件:
"Last,First,HW1,HW2,HW3,HW4,Test 1,Test 2"
我想从HW和测试中删除数字。结果将是:
"Last,First,HW,HW,HW,HW,Test ,Test"
有没有办法做到这一点?
答案 0 :(得分:0)
试试这个:
def main(ifilename, ofilename):
with open(ifilename,'r') as i, open(ofilename,'w') as o:
for line in i:
for digit in (0,1,2,3,4,5,6,7,8,9):
line = line.replace(str(digit), '')
print(line,file=o,end='')
if __name__ == '__main__':
from sys import argv
main(argv[1], argv[2])
使用命令行中的脚本,如下所示:
python my_script.py input.csv output.csv