# Numpy savetxt: change decimal separator

5 messages
Open this post in threaded view
|

## Numpy savetxt: change decimal separator

 Hello everyone, I save data to a file with the following statement: np.savetxt(fileName, transpose((average_dist, std_deviation, maximum_dist, sum_of_dist)), delimiter = ';', fmt='%6.10f') is there a possibility to change the decimal seperator from a point to comma ? And another question I import this file to excel, is there also a possiblity to create a headline for each column, that the file looks like the following example: average; standard deviation; maximum distance; sum of distances 0,26565; 0,65565; 2,353535; 25, 5656 ... ... ... Thanks, Markus_______________________________________________ NumPy-Discussion mailing list [hidden email] http://mail.scipy.org/mailman/listinfo/numpy-discussion
Open this post in threaded view
|

## Re: Numpy savetxt: change decimal separator

 On Thu, Sep 24, 2009 at 2:07 AM, wrote: Hello everyone, I save data to a file with the following statement: np.savetxt(fileName, transpose((average_dist, std_deviation, maximum_dist, sum_of_dist)), delimiter = ';', fmt='%6.10f') is there a possibility to change the decimal seperator from a point to comma ? And another question I import this file to excel, is there also a possiblity to create a headline for each column, that the file looks like the following example: I don't know how to accomplish the first task, but for the latter the following lines should work:fid = open(fileName, 'w')fid.write("average; standard deviation; maximum distance; sum of distances")np.savetxt(fid, transpose((average_dist, std_deviation, maximum_dist, sum_of_dist)), delimiter = ';', fmt='%6.10f')fid.close()  average; standard deviation; maximum distance; sum of distances 0,26565; 0,65565; 2,353535; 25, 5656 ... ... ... Thanks, Markus_______________________________________________ NumPy-Discussion mailing list [hidden email] http://mail.scipy.org/mailman/listinfo/numpy-discussion -- Gökhan _______________________________________________ NumPy-Discussion mailing list [hidden email] http://mail.scipy.org/mailman/listinfo/numpy-discussion
Open this post in threaded view
|

## Re: Numpy savetxt: change decimal separator

 In reply to this post by Markus1234 On Sep 24, 2009, at 3:07 AM, [hidden email] wrote:Hello everyone, I save data to a file with the following statement: np.savetxt(fileName, transpose((average_dist, std_deviation, maximum_dist, sum_of_dist)), delimiter = ';', fmt='%6.10f') is there a possibility to change the decimal seperator from a point to comma ? And another question I import this file to excel, is there also a possiblity to create a headline for each column, that the file looks like the following example: average; standard deviation; maximum distance; sum of distances 0,26565; 0,65565; 2,353535; 25, 5656 For the first task, I don't know if there is any direct way in numpy to change the decimal sep, but a little bit awkward trick as follows should work:mem_file = StringIO.StringIO()np.savetxt(mem_file, ... )new_data_str = mem_file.getvalue().replace('.', ',')output_file = open(fileName, 'w')output_file.write(new_data_str)output_file.close()Or you can use regex to get better match for the decimal seperator.Thanks,Junda_______________________________________________ NumPy-Discussion mailing list [hidden email] http://mail.scipy.org/mailman/listinfo/numpy-discussion