开发者

Read through an unstructured xls file

I have an .xls file which contains one column with 2,000 rows.

I want to iterate through the file and print out the data points which start with "cheap". However, the fol开发者_如何转开发lowing code doesn't work.

Help!

import xlrd
wb = xlrd.open_workbook("file.xls")

wb.sheet_names()

sh = wb.sheet_by_index(0)
lst = [sh]

for item in lst:
    print item.startswith("cheap")

    Traceback (most recent call last):
  File "C:\Python26\keywords.py", line 14, in <module>
    print item.startswith("cheap")
AttributeError: 'Sheet' object has no attribute 'startswith'


it should look like:

import xlrd
wb = xlrd.open_workbook("file.xls")

wb.sheet_names()

sh = wb.sheet_by_index(0)

for item in sh.col(0):
    value = unicode(item.value)
    if value.startswith("cheap"):
        print value
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜