Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #69737 > unrolled thread
| Started by | Anthony Papillion <papillion@gmail.com> |
|---|---|
| First post | 2014-04-05 22:52 -0500 |
| Last post | 2014-04-05 22:52 -0500 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
How can I parse this correctly? Anthony Papillion <papillion@gmail.com> - 2014-04-05 22:52 -0500
| From | Anthony Papillion <papillion@gmail.com> |
|---|---|
| Date | 2014-04-05 22:52 -0500 |
| Subject | How 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
Back to top | Article view | comp.lang.python
csiph-web