Extract values from Excel spreadsheet

二次信任 提交于 2019-12-01 23:01:51

问题


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)

What I get :

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

and I need

[150000, 140000, 300000] 

回答1:


If you use a loop you can access to the value of a cell using this function:

sheet0.cell_value(curr_row, curr_cell)


来源:https://stackoverflow.com/questions/22177313/extract-values-from-excel-spreadsheet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!