老样子:先上代码
import xlrd
excel = xlrd.open_workbook("C:/Users/Administrator/Desktop/date.xls") # 打开excel文件
sheet = excel.sheet_by_index(0) # 获取工作薄
rows: list = sheet.row_values(0) # 获取第一行的表头内容
index = rows.index('username') # 获取age列所在的列数: 1,也可以换成"password"
listindes = sheet.col_values(index) # 获取age列的所有内容
# 遍历该列所有的内容
for i in range(1, len(listindes)):
print(listindes[i])
老样子:看效果



本文展示了如何使用Python的xlrd库从Excel文件中提取'username'列的索引,并遍历获取'age'列的所有数据。通过代码实例,理解数据处理的基本步骤。
934

被折叠的 条评论
为什么被折叠?



