How can I parse this correctly?

  • Thread starter Anthony Papillion
  • Start date
A

Anthony Papillion

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top