怎样用python,读取excel中的一列数据
Python对Excel的读写主要有xlrd、copyxlwt、xlutils、openpyxl、xlsxwriter几种。
1、xlrd主要用来读百取Excel文件(Excel read)
import xlrd
worksheet = xlrd.open_workbook(u'Python操作Excel.xls')
sheet_names= worksheet.sheet_names()
for sheet_name in sheet_names:
sheet2 = worksheet.sheet_by_name(sheet_name)
print sheet_name rows = sheet2.row_values(3) # 获取第四行内容度
cols = sheet2.col_values(1) # 获取第二列内容
print rows
print cols
python操作excel,使用xlrd模块,获取某一列数据的...
概述
直接提取会报错,把array数组转换成list,即可提取,使用numpy转换
步骤详解
1、直接提取尝试:
group=[[1,2],[2,3],[3,4]]
#提取第一列元素
print(group[:,1])
#Out:TypeError: list indices must be integers or slices, not tuple
2、使用numpy转换:
import numpy as np
group=[[1,2],[2,3],[3,4]]
#numpy转化
<
本文介绍了使用Python的xlrd模块读取Excel文件,并通过实例详细讲解如何获取特定列数据。还涉及到numpy数组的操作,如转换为list以提取列数据,并提供了对numpy数组的基本操作和索引的说明。
最低0.47元/天 解锁文章

1万+

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



