我是一名新手程序员,需要一些关于Python方面的指导。我有一个包含8个列和500万行数据的文本文件,我想要在第四列的每个数值上加15。
例如:
任何建议都会很棒。
例如:
10 21 34 12 50 111 234 21 7
21 10 23 56 80 90 221 78 90
将被改为:
10 21 34 12 **65** 111 234 21 7
21 10 23 56 **95** 90 221 78 90
以下是我的脚本,它能让我隔离出该列,但当我尝试添加任何数量时,返回"TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'"。
file = open("file.txt")
column = []
for line in file:
column.append(int(line.split("\t")[3]))
print column
任何建议都会很棒。
print line.split("\t")[3]
。另外,请显示出现错误的行。最后,如果要更改第五列,为什么使用[3]
? - Tim Pietzcker