赞
踩
在Python中,使用openpyxl库来加载Excel数据文件,当Excel表格中的数据是使用公式计算得出的时候,python会直接获取该栏的计算公式,就会报错。
ValueError: could not convert string to float: '=AVERAGE(C6:K6)'
使用pandas库导入Excel数据即可解决
- import pandas as pd
-
- # 读取Excel文件
- df = pd.read_excel("达标模板.xlsx")
-
- # 使用applymap函数将公式应用到每个单元格的值上
- df = df.applymap(lambda x: eval(x) if isinstance(x, str) else x)
-
- # 打印结果
- print(df)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。