domingo, 22 de julio de 2018

Receta Python 3 No. 6-1: Leer y Escribir Datos en Formato CSV

1. Problema

Leer y escribir datos en formato CSV (Comma Separated Values).

2. Solución

Por medio de la librería csv es posible leer y escribir datos codificados en CSV (Beazly, Jones, 2013).

3. Código Python 3

Archivo Python manipular-csv.py [enlace alternativo]:
Prueba de ejecución:

['ID', 'Documento', 'Nombre', 'Ingreso', 'Telefono', 'Salario']
['DEA4CB18-8100-8773-B718-186EB2946A8A', '1630060891599', 'Maxwell Coleman', 'March 16th, 2018', '1-439-528-9645', '$9,961']
['BBE1267E-851B-5047-EED9-F86518527C2B', '1620020685899', 'Abbot Riley', 'October 21st, 2017', '1-469-920-1189', '$7,386']
['FEAE607A-0464-5F68-2E8E-068D131C9BD1', '1643061713099', 'Callum Hubbard', 'November 9th, 2017', '1-780-178-6105', '$6,843']
['1DC0E0F2-9387-665C-D99D-D4C339A683EA', '1651081664999', 'Bert Pittman', 'October 24th, 2017', '1-973-992-1822', '$8,308']
...
['A438E001-4B49-A9EE-19E7-2304DBF84021', '1647061256599', 'Steel Nieves', 'March 10th, 2018', '1-777-733-1221', '$7,863']
['23760DE7-A5BB-04B3-1305-44B69BE2398D', '1655111551899', 'Ishmael Stanton', 'April 30th, 2018', '1-343-849-0897', '$8,702']

['58EAE331-73A8-89BE-46EF-D5752ECE6E4F', '1640101982699', 'Hakeem Oneal', 'December 21st, 2017', '1-871-724-7148', '$5,979']

El contenido proviene de la lectura del archivo datos.csv [enlace alternativo].

4. Literatura & Enlaces

Beazly D, Jones B. K. (2013). Python Cookbook, Third Edition. United States: O'Reilly Media.

O

No hay comentarios:

Publicar un comentario

Envíe sus comentarios, dudas, sugerencias, críticas. Gracias.