Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何获取xlrd中包含数据的行数_Python 3.x_Excel_Xlrd - Fatal编程技术网

Python 3.x 如何获取xlrd中包含数据的行数

Python 3.x 如何获取xlrd中包含数据的行数,python-3.x,excel,xlrd,Python 3.x,Excel,Xlrd,我在python3中使用xlrd来获取行数。我有一个excel工作表,其中有1136行,但只有少数几行包含数据,其余为空。下面是一个屏幕截图: 在上面的照片中,直到第7行我们都有数据,但其余的行都是空的。我想得到包含数据的行数 import xlrd workbook = xlrd.open_workbook('Import Template-3.xlsx') sheet = workbook.sheet_by_index(0) no_of_rows = sheet.nrows print

我在
python3
中使用
xlrd
来获取行数。我有一个excel工作表,其中有
1136
行,但只有少数几行包含数据,其余为空。下面是一个屏幕截图:

在上面的照片中,直到第7行我们都有数据,但其余的行都是空的。我想得到包含数据的行数

import xlrd

workbook = xlrd.open_workbook('Import Template-3.xlsx')
sheet = workbook.sheet_by_index(0)

no_of_rows = sheet.nrows
print(no_of_rows)

但我认为上面的代码将
1136
打印为行数。是否有任何函数/方法可用,通过这些函数/方法,我们只能获取包含数据的行数。谢谢

如果只想转换包含数据的行,请使用

xl = pd.ExcelFile(file)
sh = list(xl.sheet_names)

for i in sh:
    df = pd.read_excel(file,sheet_name=i, comment='#')
    print(df.count())
    df_derived = df[df['AnimalID'] == i] 
    print(df_derived.count())
    df_list = df_derived.values.tolist()   
取决于一列标识