欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 产业 > ValueError: could not convert string ‘date‘ to float64 at row 0, column 1.

ValueError: could not convert string ‘date‘ to float64 at row 0, column 1.

2024/10/24 20:14:13 来源:https://blog.csdn.net/Lauxuxu/article/details/141938738  浏览:    关键词:ValueError: could not convert string ‘date‘ to float64 at row 0, column 1.

ValueError:无法将字符串“date”转换为第0行第1列的float64。

解决办法:

通过以下代码检查自己的数据,查找问题,逐一改正。

import csv
def find_blank_or_invalid_cells(file_path):blank_cells = []invalid_cells = []with open(file_path, 'r', newline='', encoding='utf-8') as csvfile:reader = csv.reader(csvfile)for index, row in enumerate(reader):for column, cell in enumerate(row):if cell.strip() == '':blank_cells.append((index, column))elif not cell.replace('.', '').isdigit():invalid_cells.append((index, column))return blank_cells, invalid_cells
# 给定csv文件路径
file_path = './data.csv'
# 查找空白单元格和无效字符串单元格
blank_cells, invalid_cells = find_blank_or_invalid_cells(file_path)
# 打印结果
print("空白单元格位置:", blank_cells)
print("无效字符串位置:", invalid_cells)

运行结果发现数据第一列有问题,经检查发现第一列是日期,不是数值形式,进行修改。(因为我的不需要日期,所以直接把第一列删去了,大家根据自己情况修改。)

修改后:感谢博主的解答

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com