Peter Perez wrote:
>
> Thanks to Kevin and Andrew for your suggestions. I do know the exact
> number of columns and rows of the files, but I forgot to mention that
> the files contain headers for each column. I realized that this is
> important, since I tried the abovementioned solutions and they both seem
> to require only-numeric data. How can I tell python to ignore the
> headers and import only the numeric data in the columns? Thanks so much
> for your help. Best Regards, Peter
You could just wrap the function call to int() or float() in a
try/except block. That would catch the exception and handle it properly:
col1 = []
col2 = []
def populateColumns(row):
col1.append(row[0])
col2.append(row[1])
r = csv.reader(open(fname, 'rb'))
for row in r:
try:
row = map(float, row)
populateColumns(row)
except:
pass
When you try to map the float() function to a string, it will throw an
error. The try/except block will take care of that for you.
- khill