Skip to content

Instantly share code, notes, and snippets.

@fccoelho
Created June 13, 2016 12:48
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 fccoelho/dad2c483c16e844d3d9de310bcb84be3 to your computer and use it in GitHub Desktop.
Save fccoelho/dad2c483c16e844d3d9de310bcb84be3 to your computer and use it in GitHub Desktop.
Pandas FWF bug
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
12 13 5 0 11AVENIDA GOVERNADOR EDMUNDO PINTO 72 ACRELANDIA 01 00100169945000
12 13 5 0 11AVENIDA GOVERNADOR EDMUNDO PINTO 72 ACRELANDIA 06AUTO POSTO NORTE 1 00100169945000
12 13 5 0 11AVENIDA GOVERNADOR EDMUNDO PINTO 92 ACRELANDIA 01 00100169945000
12 13 5 0 11AVENIDA GOVERNADOR EDMUNDO PINTO 112 ACRELANDIA 01 00100169945000
12 13 5 0 11AVENIDA GOVERNADOR EDMUNDO PINTO 122 ACRELANDIA 01 00100169945000
12 13 5 0 11AVENIDA GOVERNADOR EDMUNDO PINTO 0SN ACRELANDIA 01 00100169945000
12 13 5 0 11AVENIDA GOVERNADOR EDMUNDO PINTO 152 ACRELANDIA 01 00100169945000
12 13 5 0 11AVENIDA GOVERNADOR EDMUNDO PINTO 171 ACRELANDIA 01 00100169945000
12 13 5 0 11AVENIDA GOVERNADOR EDMUNDO PINTO 182 ACRELANDIA 01 00100169945000
12 13 5 0 11AVENIDA GOVERNADOR EDMUNDO PINTO 175FNS ACRELANDIA 01 00100169945000
#!/usr/bin/env python3
import pandas as pd
col_specs = [
(0, 2),
(2, 7),
(7, 9),
(9, 11),
(11, 15),
(15, 16),
(16, 36),
(36, 66),
(66, 126),
(126, 134),
(134, 141),
(141, 161),
(161, 171),
(171, 191),
(191, 201),
(201, 221),
(221, 231),
(231, 251),
(251, 261),
(261, 281),
(281, 291),
(291, 311),
(311, 321),
(321, 336),
(336, 351),
(351, 411),
(411, 471),
(471, 473),
(473, 513),
(513, 514),
(514, 544),
(544, 547),
(547, 550),
(550, 558),
]
df = pd.read_fwf('test.csv', colspecs=col_specs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment