Pandas 2.0.0 似乎thousands=','
在解析Int64
对象时没有正确考虑:
import io
pd.read_csv(io.StringIO('''a\n22,922'''), sep='\t', dtype={'a': 'Int64'}, thousands=',')
具体错误是:
Traceback (most recent call last):
File pandas/_libs/lib.pyx:2280 in pandas._libs.lib.maybe_convert_numeric
ValueError: Unable to parse string "22,922"
是否有一种解决方法不涉及返回到 un-nullableint
或转换为float
?我已经确认这适用于旧的 dtypesdtype={'a': 'int'}
和dtype={'a': 'float'}
.
实际上,即使您不指定参数,也会触发错误
thousands
。这是一个悬而未决的问题(请参阅 GH52594)。当使用引擎调用时,您还不能应用可为空的数据类型。read_csv
C
一个简单的解决方法是使用
astype
:默认引擎是
c
,您要使用python
输出