从 Excel 电子表格中提取值 [英] Extract values from Excel spreadsheet
本文介绍了从 Excel 电子表格中提取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从单词列表中删除一些单词.我有一个包含重复出现的词的列表,我想摆脱它,但我不知道.我不知道我是否需要使用整个循环或正则表达式.
I want to remove some words from a list of words. I have a list with a recurring word and I want to get rid of it and I have no idea. I don't know whether I need to use a whole loop or regex.
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]
推荐答案
如果您使用循环,您可以使用此函数访问单元格的值:
If you use a loop you can access to the value of a cell using this function:
sheet0.cell_value(curr_row, curr_cell)
这篇关于从 Excel 电子表格中提取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文