赞
踩
python操作excel主要用到xlrd和xlwt这两个库,即xlrd是读excel,xlwt是写excel的库
import xlrd
def read_excel():
path = './Sec_BLE_Zigbee.xlsx'
book = xlrd.open_workbook(path) # 打开一个工作表
for sheet in book.sheets():# book.sheets()#返回book中所有工作表的名字
print(sheet.name)# Sec_BLE_Zigbee,zig
book1 = book.sheet_by_name('Sec_BLE_Zigbee')# 通过表明获取表
book2 = book.sheet_by_index(0)# 通过索引获取表
nrows = book1.nrows# 表的行数
print(nrows)
for i in range(nrows):
print(book1.row_values(i))# 每一行的值
if __name__ == '__main__':
read_excel()
xlrd
安装方法pip install xlrd
报错 读取xlsx文件错误:xlrd.biffh.XLRDError: Excel xlsx file; not supported
可能是xlrd版本太高了。需要降级
参考https://blog.csdn.net/Erickkkkkk/article/details/124696751
sheet_name
total = pd.read_excel(cost_total_path,sheet_name='主板')
data.to_excel(file_path, encoding="gb2312", index=0, float_format='%.7f')
float_format
设置float
类型数据保存的小数的格式
两列元素点乘
data['扩展成本'] = data.apply(lambda x: np.multiply(x['Quantity'], x['物料成本不含税']), axis=1)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。