xlrd 数据提取 python

xlrd data extraction python

我正在使用 xlrd 进行数据提取,我已经为我的项目提取了 8 列输入。每列数据大约有 100 行。我的代码如下:

wb = xlrd.open_workbook('/Users/Documents/Sample_data/AI_sample.xlsx')

sh = wb.sheet_by_name('Sample')

x1 = sh.col_values( + 0)[1:]
x2 = sh.col_values( + 1)[1:]
x3 = sh.col_values( + 2)[1:]
x4 = sh.col_values( + 3)[1:]
x5 = sh.col_values( + 4)[1:]
x6 = sh.col_values( + 5)[1:]
x7 = sh.col_values( + 6)[1:]
x8 = sh.col_values( + 7)[1:]

现在我想创建一个输入数组,它给出 8 列中的每一行。 例如:如果这是我的 8 列数据

x1   x2   x3   x4   x5   x6   x7   x8   
1    2    3    4    5    6    7    8
7    8    6    5    2    4    8    8
9    5    6    4    5    1    7    5   
7    5    6    3    1    4    5    6

我想要这样的东西:x1, x2, x3, x4, x5, x6 ([1,2,3,4,5,6,7,8]) 所有 100 多行。

我本可以进行逐行提取,但是对 100 多行进行提取实际上非常困难。那我该怎么做。我也知道可以使用 np.array 来完成。但是我不知道怎么办。

您也可以尝试 openpyxl 类似于 xlrd

的东西
from openpyxl import load_workbook,Workbook
book  = load_workbook(filename=file_name)
sheet = book['sheet name']
for row in sheet.rows:
    col_0           = row[0].value
    col_1           = row[1].value

我以前更喜欢 openpyxl 而不是 xlrd

我发现这段代码非常有用

X = np.array([x1, x2, x3, x4, x5, x6, x7, x8])
return X.T