Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created July 23, 2018 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/3f3fade2d5019cc750606810dd69a8e4 to your computer and use it in GitHub Desktop.
Save Fhernd/3f3fade2d5019cc750606810dd69a8e4 to your computer and use it in GitHub Desktop.
Escribir y leer datos en formato CSV. OrtizOL.
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment