Reputation: 25366
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?
Upvotes: 22
Views: 27696
Reputation: 143
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="")
Upvotes: 0
Reputation: 4359
The header and footer text are added as comments. If you want to change the comment identifier, pass the comments
option (the default is #
):
np.savetxt("foo.csv", x, delimiter=",", header="ID,AMOUNT",
fmt="%i", comments='')
As documented here.
Upvotes: 43