Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #69737 > unrolled thread

How can I parse this correctly?

Started byAnthony Papillion <papillion@gmail.com>
First post2014-04-05 22:52 -0500
Last post2014-04-05 22:52 -0500
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  How can I parse this correctly? Anthony Papillion <papillion@gmail.com> - 2014-04-05 22:52 -0500

#69737 — How can I parse this correctly?

FromAnthony Papillion <papillion@gmail.com>
Date2014-04-05 22:52 -0500
SubjectHow can I parse this correctly?
Message-ID<mailman.8932.1396756706.18130.python-list@python.org>
Hello Everyone,

I'm working with historical earthquake data and I have a tab delimited
file. I'm using the csv module with the \t delimiter to denote it's
tab separated and it's working fine. I've set things up loike this:

import csv

f = open('earthquakes.tsv')
r = csv.DictReader(f, delimiter='\t')

for row in r:
    print row['YEAR']

This works fine. But, I am needing to do date addition/subtraction
using datetime and so I need these dates as integers. When I try to
cast them like this:

print int(row['YEAR'])

I am told by the interpreter:

Traceback (most recent call last):
  File "analyze.py", line 14, in <module>
    print int(row['MONTH'])
ValueError: invalid literal for int() with base 10: ''

What am I doing wrong? Am I not understanding HOW to cast?

Thanks,
Anthony

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web