Hi all,
I have an excel doc that has some information about various countries and I want to get a list of all the countries, which is in Column A. But, when I try to iterate over column A, I get this error:
I don't quite understand, because if I try
etc...it prints all the correct information.
Thanks for any help!
Patrick
Here's the code:
I have an excel doc that has some information about various countries and I want to get a list of all the countries, which is in Column A. But, when I try to iterate over column A, I get this error:
Code:
Traceback (most recent call last): File "C:\Python24\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript exec codeObject in __main__.__dict__ File "C:\Documents and Settings\PW\My Documents\Python\excel\read_matrix_clean.py", line 18, in ? if countries[n]==countries[n+1]: IndexError: list index out of range
Code:
print countries[n] print countries[n+1] print countries[n+2]
Thanks for any help!
Patrick
Here's the code:
Code:
import xlrd path_file = "c:\\data.xls" book = xlrd.open_workbook(path_file) Counts = book.sheet_by_index(1) countries= Counts.col_values(0,start_rowx=1, end_rowx=None) n = 0 x = len(countries) print x while n<x: if countries[n]==countries[n+1]: del countries[n+1] else: n = n+1 print countries
Comment