python - 为什么 Pandas 在读取 csv 文件时忽略 doublequote=True
问题描述
我有一个包含如下数据的 CSV 文件:
123,"this is text",123,123,123,"""This is text, it is quoted and has a comma"""
我正在阅读这个 CSV 文件pandas
,并且这一行应该被解释为:
col1 | col2 | col3 | col4 | col5 | col6
123 | this is text | 123 | 123 | 123 | "This is text, it is quoted and has a comma"
但是,我不断得到
预期 N 列,但在行号中找到 N+1 ....
来自 的错误pandas
。
我在我的本地机器的 docker 容器中测试了这个,相同的 python 和pandas
服务器中的版本,在我的机器上它工作正常,但在服务器上,它没有。
这是我在两种情况下都使用的命令:
df = pandas.read_csv(csv_path, dtype=str, sep=',', keep_default_na=True, quotechar='"', doublequote=True)
如果我在我的本地 docker 容器中将 doublequote 更改为False
,那么我会得到同样的错误,但True
它可以工作,但在服务器上,它既不工作False
也不工作True
,看起来 doublequote 什么也没做。
我可以看到的一个区别是 GCC python 使用,在服务器上它说 GCC 4.8.5 而在我的本地 docker 容器上它说 GCC 8.3.0,这可能是问题吗?如果是,如何在服务器上指定?
解决方案
我刚刚使用您提供的信息创建了两个文件(一个 .csv 和一个 .txt 文件)。两种方法都对我有用。
pd.read_csv('file.csv', header=None)
pd.read_csv('file.txt', header=None)
也许你可以尝试另一个版本的熊猫。我的是 1.2.5,它按预期工作。
推荐阅读
- javascript - react.js 如何实现多输入搜索?
- python - pandas 根据组 min max 动态交叉加入
- r - R - 仅识别列中以 A 和 B 结尾的字符串
- google-sheets - 如何在谷歌表格中选择输入行
- linux - 无法连接到 Docker 守护进程
- python - Beautifulsoup 从位于单词网格下的表格网格中获取文本
- flutter - Flutter:后缀图标使文本不居中
- flutter - 在颤振中,有没有办法以编程方式在 CountryPickerDropdown 中设置初始值?
- keychain - 什么是本地设备钥匙串?
- node.js - Javascript 函数正在使用节点 v14.7.0 改变参数