Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

266
Vistas
Save numpy array to CSV without scientific notation

I was able to calculate the mean, min and max of A:

 import numpy as np

 A = ['33.33', '33.33', '33.33', '33.37']

 NA = np.asarray(A)
 NA = NA.astype(float)
 AVG = np.mean(NA, axis=0)
 MN = np.min(NA, axis=0)
 MX = np.max(NA, axis=0)

 print AVG, MN, MX

What is the easiest way to save those results to a csv documento using python? I dont have one so it needs to be created.

If I use this:

 np.savetxt('datasave.csv', (AVG,MN,MX), delimiter=',')

It will show as scientific notation in csv. How do I not get that but float?

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

In [153]: print(AVG, MN, MX)
33.34 33.33 33.37

The default write:

In [154]: np.savetxt('test.txt',(AVG, MN, MX), delimiter=',')
In [155]: cat test.txt
3.333999999999999631e+01
3.332999999999999829e+01
3.336999999999999744e+01

write with a custom fmt:

In [156]: np.savetxt('test.txt',(AVG, MN, MX), delimiter=',', fmt='%f')
In [157]: cat test.txt
33.340000
33.330000
33.370000

Or if you want values on one line, make it a 2d array (or equivalent with extra []), so it writes one row per line:

In [160]: np.savetxt('test.txt',[[AVG, MN, MX]], delimiter=',', fmt='%f')
In [161]: cat test.txt
33.340000,33.330000,33.370000

There are other parameters that you can experiment with.

over 4 years ago · Santiago Trujillo Denunciar

0

You can use the CSV module

import csv
f = open('New file.csv',"wb")
writer = csv.writer(f)
for row in [AVG, MN, MX]:
    writer.writerow(row)

f.close()
over 4 years ago · Santiago Trujillo Denunciar

0

A CSV or Comma Separated Value file is precisely just that a file that separates info with commas.

For example: this info will end up like

<table border="1">
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>Gender</th>
</tr>
</thead>
<tbody>
<tr>
<td>Luis</td>
<td>45</td>
<td>M</td>
</tr>
<tr>
<td>Anna</td>
<td>30</td>
<td>F</td>
</tr>
<tr>
<td>Brian</td>
<td>28</td>
<td>M</td>
</tr>
</tbody>
</table>

Name,Age,Gender
Luis,45,M
Anna,30,F
Brian,28,M

Python has already a built-in module for this, the csv module, you can get some documentation here: https://docs.python.org/3/library/csv.html

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda