我正在使用python(xlrd包)从excel表中提取数据。随着原始数据我得到一些垃圾数据,请帮我删除那些
获取垃圾值,如[text:u如下:
[text:u'NAME',text:u'JACK']
<CODE>
from xlrd import open_workbook
book = open_workbook('C:/Users/arun/Desktop/EX.xls')
sheet0 = book.sheet_by_index(0)
#sheet1 = book.sheet_by_index(1)
print sheet0.col(0)
print sheet0.col(2)
print sheet0.col(3)
print sheet0.col(4)
print sheet0.col(5)
print sheet0.col(6)
print sheet0.col(7)
print sheet0.col(8)
print sheet0.col(9)
print sheet0.col(10)
print sheet0.col(12)
print sheet0.col(13)
print sheet0.col(14)
print sheet0.col(15)
print sheet0.col(16)
print sheet0.col(17)
print sheet0.col(18)
print sheet0.col(19)
print sheet0.col(20)
print sheet0.col(21)
print sheet0.col(22)
print sheet0.col(23)
print sheet0.col(24)
print sheet0.col(25)
print sheet0.col(26)
print sheet0.col(27)
</CODE>
答案 0 :(得分:4)
您的“垃圾”看起来像是“文本”类型的xlrd Cell
列表。也就是说,我认为它不是垃圾;它是由xlrd创建的正常返回值。如果您想要列中的值(例如,第0列),请尝试
print sheet0.col_values(0)
请参阅https://secure.simplistix.co.uk/svn/xlrd/trunk/xlrd/doc/xlrd.html#sheet.Sheet.col_values-method
答案 1 :(得分:1)
我发现使用str(sheet0.col(0))将删除文本:u output。