python numpy.savetxt header has extra character #

Viewed 19007

I am using the following to save the numpy array x with a header:

np.savetxt("foo.csv", x, delimiter=",", header="ID,AMOUNT", fmt="%i")

However, if I open "foo.cv", the file looks like:

# ID,AMOUNT
21,100
52,120
63,29
:

There is an extra # character in the beginning of the header. Why is that and is there a way to get rid of it?

2 Answers

it inserts the # because that line is a comment, and the default character for comments is the symbol #,

If you want to get rid of it, pass comments='' as option to savetxt.

numpy.savetxt('reference_vect_tool.00001.txt',riferimento,fmt='%.6f',header="reference", comments="")
Related