This is the line that is giving you the error:
outfile.write("".join(map(str,columns)+"\n"))
When you read the Traceback error, the last part will usually show you the line number in your script that generated the issue, so you should check that first.
The way the line currently reads, +"\n"
is part of the join
function, when it should be part of the write
method:
outfile.write("".join(map(str,columns)) + "\n")
If your intention was to write each average from columns
on a new line, and also insert a new line at the end of the list, you need this:
outfile.write("\n".join(map(str,columns)) + "\n")
More: http://docs.python.org/2/library/stdtypes.html#str.join