从Excel spreadsh中提取值

2024-04-28 20:30:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我想从单词列表中删除一些单词。我有一张单子,上面有一个反复出现的单词,我想把它去掉,但我不知道。我不知道我是需要使用整个循环还是正则表达式。在

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)

我得到的是:

^{pr2}$

我需要

[150000, 140000, 300000] 

Tags: textfrom列表namescellopenvariables单词