import numpy as np # 循环遍历每一个单元格 for row in ws.iter_rows(): for cell in row: # 判断单元格是否包含% if '%' in str(cell.value): # 将单元格格式设置为数字格式 cell.number_format = '0.00%' # 将单元格值除以100并重新赋值给单元格 cell.value = float(cell.value.strip('%')) / 100 以上代码执行后报错信息:AttributeError: module 'numpy' has no attribute 'float'. `np.float` was a deprecated alias for the builtin `float`. To avoid this error in existing code, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.,麻烦修正报错并输出代码
时间: 2023-12-06 11:41:03 浏览: 116
python 3.74 运行import numpy as np 报错lib\site-packages\numpy\__init__.py
import openpyxl
# 打开 Excel 文件
wb = openpyxl.load_workbook('example.xlsx')
# 选择第一个工作表
ws = wb.active
# 循环遍历每一个单元格
for row in ws.iter_rows():
for cell in row:
# 判断单元格是否包含%
if '%' in str(cell.value):
# 将单元格格式设置为数字格式
cell.number_format = '0.00%'
# 将单元格值除以100并重新赋值给单元格
cell.value = float(cell.value.strip('%')) / 100
wb.save('example.xlsx')
阅读全文