problem to separate attributes by columns in .csv file

0

The program should read "a table" in python and then write it in a csv file, what I have until now is:

What is above the main code are functions that simply serve to add names, ages and scores (I do not see it necessary to add it).

############################## Programa principal ##############################


# Se pedirá la cantidad de personas que serán ingresadas.
while True:
    try:
        n = int(input("\nIngrese el número de personas:   "))

        if type(n) is int and n > 0:
            break
        else:
            print("\nIngrese un número de personas válido (mayor de 0)")
    except ValueError:
        print("\nERROR\nPor  favor solo ingrese números enteros "
              "que sen mayores de cero")

# Se guarda la lista creada con los nombres que ingresó el usuario.
Nombres = ingresar_nombre(n)
# Se guarda la lista creada con las edades que ingresó el usuario.
Edades = ingresar_edad(n)
# Se guarda la lista creada con los puntajes que ingresó el usuario.
Puntajes = ingresar_puntaje(n)

# Se empaquetan los datos anteriores en una sola lista la cual en cada posición
# contiene una tupla con (Nombre, Edad, puntaje).
carpeta = zip(Nombres, Edades, Puntajes)

# Ordena la todos los elemetos de la lista.
carpeta_ord = sorted(carpeta)
titulos = ["NOMBRE", "EDAD", "PUNTAJE"]

# Imprime los títulos de la tabla
print('\n{:^20}{:^20}{:^20}'.format("NOMBRE", "EDAD", "PUNTAJE"))

# Imprime los elementos correspondientes a cada columna de la tabla.
for nombre, edad, puntaje in carpeta_ord:
    print("{:^20}{:^20}{:^20}".format(nombre, edad, puntaje))

# Crea el archivo csv

archivo = open('tabla.csv', 'w', newline="")
salida = csv.writer(archivo)
salida.writerow(titulos)
salida.writerows(carpeta_ord)
del salida

archivo.close()

The program prints this "table" (I clarify that I can not use pandas or similar libraries):

The program prints this "table" (I clarify that I can not use pandas or similar libraries):

And in excel it puts this to me, I need everything to be separated in the corresponding columns.

How do I make each attribute to put it in a different column?

    
asked by Richard A. Ramos Trujillo 01.11.2017 в 05:12
source

2 answers

1

Richard understand that the output that you have is good, what happens is that when you open it with exel you have to put or tell you to use commas as separators, I share two links on the subject:

1 - link

2 - link

I hope it helps you

    
answered by 01.11.2017 в 16:26
0

When saving the data in the file, separate the data with a semicolon ( ; ) like this:

Nombre;Edad;Puntaje
Samir;23;100
Andres;20;23
Jairo;18;73
    
answered by 01.11.2017 в 07:59