CSV文件分隔符转换

CSV文件系统默认分隔符是逗号(,),但是如果自定义过分隔符,再次保存就会变成分号(;),此时再用逗号去读数据时程序会报错。

例如设置csv格式如下:

 

Python方法

pd.read_csv(file_path, delimiter=",")
使用逗号去读取时会报错

Traceback (most recent call last):
File "xxx\Python39\lib\site-packages\pandas\core\indexes\base.py", line 3652, in get_loc
return self._engine.get_loc(casted_key)
File "pandas\_libs\index.pyx", line 147, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\index.pyx", line 176, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\hashtable_class_helper.pxi", line 7080, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas\_libs\hashtable_class_helper.pxi", line 7088, in pandas._libs.hashtable.PyObjectHashTable.get_item
此时修改为默认系统分隔 或者改为Decimal用句号,Thousands用逗号,再次保存csv文件则不会有此问题

注意 保存时选择逗号分隔:

 

 参考:

https://zh-cn.extendoffice.com/documents/excel/7228-excel-change-delimiter-when-saving-as-csv.html

posted @ 2023-08-08 09:12  蜗牛果果  阅读(1781)  评论(0编辑  收藏  举报