【问题标题】:From Excel sheet how to extract specific row with condition to be satisfy从Excel工作表中如何提取满足条件的特定行
【发布时间】:2018-07-19 07:14:56
【问题描述】:
import xlrd
workbook=xlrd.open_workbook("22nd report (1).xls")
sheet = workbook.sheet_by_index(1)
c=sheet.cell_value(0,0)
for row in range(sheet.nrows):#total no of columns is 11 
    x= sheet.cell_value(row,2)
    #print(x)
    c=str(x)
    A="18"
    p=int(c)
    if(A in c):
        for col in range(sheet.ncols):
            print sheet.cell_value(x,col)

显示错误:- 值错误:int() 的字面量无效,底数为 10:'1.0'

【问题讨论】:

    标签: python .net python-unittest


    【解决方案1】:

    我不太确定您的实际问题是什么,但在上面的代码中,值 '1.0' 不能转换为 int,因为它是浮点数的字符串表示形式。

    你可以考虑使用p = int(float(c))

    但是你再也不会使用 p.... 所以你还不如删除该行...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-11
      • 1970-01-01
      • 2011-07-12
      • 2016-10-24
      相关资源
      最近更新 更多