I have a fixed length text document that I would like to parse and output to a CSV file and add a header to the newly created document that is not in the raw data. Below is the code I have for parsing based on column width.
import pandas as pd
path = '5010.txt'
col_specification =[(1, 12), (13, 18), (19, 26), (27, 31), (32, 39), (40, 47), (48, 57), (58, 62), (63, 67), (68, 72), (73, 77), (78, 78), (79, 83), (84, 84), (85, 86), (87, 92),
(93, 97), (98, 98), (99, 103), (104, 104), (105, 106), (107, 112), (113, 120), (121, 128), (129, 129), (130, 131), (132, 134), (135, 139), (140, 155), (156, 171),(172, 187), (188, 203),
(204, 213), (214, 221),]
data = pd.read_fwf(path, colspecs=col_specification)
How do I output data to a CSV file with a header?
5010.txtbut with a header?