Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #69737
| From | Anthony Papillion <papillion@gmail.com> |
|---|---|
| Date | 2014-04-05 22:52 -0500 |
| Subject | How can I parse this correctly? |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.8932.1396756706.18130.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
How can I parse this correctly? Anthony Papillion <papillion@gmail.com> - 2014-04-05 22:52 -0500
csiph-web