Fhernd icon

manipular-csv.py

Fhernd | PRO | 07/23/18 04:28:03 AM UTC | 0 ⭐ | 2735 👁️ | Never ⏰ | []
Python |

840 B

|

None

|

0 👍

/

0 👎

import csv
 
# Lectura de CSV:
with open('datos.csv') as f:
    datos_csv = csv.reader(f)
    encabezado = next(datos_csv)
 
    print(encabezado)
 
    for registro in datos_csv:
        print(registro)
 
# Escritura de CSV:
encabezados = ['ID', 'Documento', 'Nombre', 'Ingreso', 'Telefono', 'Salario']
 
filas = [('DEA4CB18-8100-8773-B718-186EB2946A8A', '1630060891599', 'Maxwell Coleman', 'March 16th, 2018', '1-439-528-9645', '$9,961'),
         ('10B867E0-D1FC-9861-56F0-33F8BA200D13', '1611082791499', 'Vladimir Long', 'September 5th, 2017', '1-308-724-5242', '$8,907'),
         ('92946EC2-3EA0-18BF-9841-F563E8157CE7', '1669092182599', 'Macon Estrada', 'August 13th, 2017', '1-312-687-9395', '$7,527')]
 
with open('datos_2.csv', 'w') as f:
    datos_csv = csv.writer(f)
    datos_csv.writerow(encabezados)
    datos_csv.writerows(filas)

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎