Advertisement
Fhernd

manipular-csv.py

Jul 22nd, 2018
1,841
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. import csv
  2.  
  3. # Lectura de CSV:
  4. with open('datos.csv') as f:
  5.     datos_csv = csv.reader(f)
  6.     encabezado = next(datos_csv)
  7.  
  8.     print(encabezado)
  9.  
  10.     for registro in datos_csv:
  11.         print(registro)
  12.  
  13. # Escritura de CSV:
  14. encabezados = ['ID', 'Documento', 'Nombre', 'Ingreso', 'Telefono', 'Salario']
  15.  
  16. filas = [('DEA4CB18-8100-8773-B718-186EB2946A8A', '1630060891599', 'Maxwell Coleman', 'March 16th, 2018', '1-439-528-9645', '$9,961'),
  17.          ('10B867E0-D1FC-9861-56F0-33F8BA200D13', '1611082791499', 'Vladimir Long', 'September 5th, 2017', '1-308-724-5242', '$8,907'),
  18.          ('92946EC2-3EA0-18BF-9841-F563E8157CE7', '1669092182599', 'Macon Estrada', 'August 13th, 2017', '1-312-687-9395', '$7,527')]
  19.  
  20. with open('datos_2.csv', 'w') as f:
  21.     datos_csv = csv.writer(f)
  22.     datos_csv.writerow(encabezados)
  23.     datos_csv.writerows(filas)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement