2014-03-04 95 views
3

我想從單詞列表中刪除一些單詞。我有一個反覆出現的單詞列表,我想擺脫它,我不知道。我不知道我是否需要使用整個循環或正則表達式。從Excel電子表格中提取值

from xlrd import open_workbook,error_text_from_code 

book = open_workbook(inp) 

sheet0 = book.sheet_by_index(0) 

x = 0 
y = 0 
countr = sheet0.nrows 
countc = sheet0.ncols 
names = '' 
variables = [] 
"different variables-----------------" 
while x < countr -1: 
    x = x+1 
    y = y+1 
    cell = sheet0.cell(y,0) 

names = names+ str(cell) 
cell = sheet0.cell(y,1) 

variables.append(cell) 

country_text = names 
countries = ', '.join(re.findall("('.*?')", country_text)) 
countries = countries.split() 

print (variables) 
print (countries) 

我得到什麼:

[number:150000.0, number:140000.0, number:300000.0] 

,我需要

[150000, 140000, 300000] 
+0

你是如何從第一個stri獲得「青蛙」,「豬」,「狗」,「原木」 NG?他們似乎沒有任何關係。 – Kevin

+0

這看起來很不合適 –

+0

我沒有得到青蛙字符串。我需要從我的第一個字符串的青蛙字符串相同的佈局。 – user3379346

回答

0

如果你使用一個循環,你可以使用此功能接入小區的值:

sheet0.cell_value(curr_row, curr_cell) 
相關問題