ElinaElizabeth 发表于 2020-10-17 20:48:26

请帮我看看为什么不能读取文件

import xlrd
import numpy as np

file_name = xlrd.open_workbook('C:\Users\swift\Desktop\002142.SZ宁波.xlsx')
try:
    im_sheet = file_name.sheet_by_name('Sheet1')
except:
    print('无',format(file_name))
row_num = im_sheet.nrows
col_num = im_sheet.ncols

stdbox=[]
for i in range(1,row_num):
    stdbox.append(im_sheet.cell(i,3))
    if len(stdbox) == 5:
       average = np.mean(stdbox)
       print(average)
       stdbox=[]

疾风怪盗 发表于 2020-10-17 20:52:40

文件可以读取啊,就是后面需要修改下,获取的是cell的value,而且文件也必须是纯数字,才能用np.mean,否则就是报错
import xlrd
import numpy as np

file_name = xlrd.open_workbook('1.xlsx')
try:
    im_sheet = file_name.sheet_by_name('Sheet1')
except:
    print('无',format(file_name))
row_num = im_sheet.nrows
col_num = im_sheet.ncols

stdbox=[]
for i in range(1,row_num):
    stdbox.append(im_sheet.cell(i,3).value)
    if len(stdbox) == 5:
       average = np.mean(stdbox)
       print(average)
       stdbox=[]
页: [1]
查看完整版本: 请帮我看看为什么不能读取文件