Created
July 23, 2018 04:28
-
-
Save Fhernd/3f3fade2d5019cc750606810dd69a8e4 to your computer and use it in GitHub Desktop.
Escribir y leer datos en formato CSV. OrtizOL.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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