【问题标题】:Extract values from Excel spreadsheet从 Excel 电子表格中提取值
【发布时间】:2014-04-06 07:18:24
【问题描述】:

我想从单词列表中删除一些单词。我有一个包含重复单词的列表,我想摆脱它,但我不知道。我不知道我是否需要使用整个循环或正则表达式。

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] 

【问题讨论】:

  • 你是如何从第一个字符串中得到'Frogs', 'Hogs', 'Dogs', 'Logs' 的?他们之间似乎没有任何关系。
  • 这似乎很不合理
  • 我没有拿到青蛙弦。我需要与我的第一个字符串相同的青蛙字符串布局。
  • 所以你想要'usa', 'uk', 'netherlands'?一开始你为什么不这么说?
  • 如果我问自己“他面临的真正问题是什么?”,我认为您正在使用xlrd 并且拥有Cell 对象而不是字符串和数字。如果是这样,this question 可能会有用。

标签: python python-3.x xlrd


【解决方案1】:

如果您使用循环,则可以使用此函数访问单元格的值:

sheet0.cell_value(curr_row, curr_cell)

【讨论】:

    猜你喜欢
    • 2017-06-18
    • 1970-01-01
    • 2017-12-31
    • 2011-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-17
    相关资源
    最近更新 更多