当前位置:   article > 正文

【常见问题】ValueError: could not convert string to float: ‘=AVERAGE(C6:K6)‘_python 读取excel 报错 valueerror: could not convert st

python 读取excel 报错 valueerror: could not convert string to float

1、问题

        在Python中,使用openpyxl库来加载Excel数据文件,当Excel表格中的数据是使用公式计算得出的时候,python会直接获取该栏的计算公式,就会报错。

ValueError: could not convert string to float: '=AVERAGE(C6:K6)'

2、解决方法

        使用pandas库导入Excel数据即可解决

  1. import pandas as pd
  2. # 读取Excel文件
  3. df = pd.read_excel("达标模板.xlsx")
  4. # 使用applymap函数将公式应用到每个单元格的值上
  5. df = df.applymap(lambda x: eval(x) if isinstance(x, str) else x)
  6. # 打印结果
  7. print(df)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/木道寻08/article/detail/940010
推荐阅读
相关标签
  

闽ICP备14008679号