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()
取决于一列标识