python 读取excel数据
# encoding:utf-8 import xlrd from pandas.core.frame import DataFrame import numpy as np import numpy def readExcelFile(filename): """ 读取XLS,XLSX文件 :return: """ workbook = xlrd.open_workbook(filename=filename) booksheet = workbook.sheet_by_index(0) colname = booksheet.row_values(0) tmp_lst = [] for i in range(1,booksheet.nrows): mid_value = booksheet.row_values(i) tmp_lst.append(mid_value) data = DataFrame(tmp_lst) data.columns = colname mean_lst = list(data.mean()) std_lst = list(data.std()) mean_array = numpy.array(mean_lst) std_array = numpy.array(std_lst) add_array = list(mean_array + std_array) cut_array = list(mean_array - std_array) data.loc['add_array'] = add_array data.loc['cut_array'] = cut_array print(data) data.to_csv( 'new.csv', index=False) filename = 'data.xlsx' readExcelFile(filename)