[Tutor] mapping header row to data rows in file

eryksun eryksun at gmail.com
Thu Jun 27 11:54:15 CEST 2013


On Thu, Jun 27, 2013 at 2:50 AM, Peter Otten <__peter__ at web.de> wrote:
>
> I'd prefer a csv.reader(), and if you have control over the table format you
> should remove the extra whitespace in the source data.

Say you AA.csv opened as f:

    >>> import csv
    >>> reader = csv.DictReader(f, skipinitialspace=1)

    >>> next(reader)
    {'Date': '22-Nov-2012', 'Series': 'EQ', 'Symbol': 'STER', 'Prev_Close': '9'}
    >>> next(reader)
    {'Date': '29-Nov-2012', 'Series': 'EQ', 'Symbol': 'STER',
'Prev_Close': '10'}

and so on.


More information about the Tutor mailing list