Pandas 2.0.0在解析Int64
对象时似乎没有正确考虑thousands=','
:
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"
有没有一种解决方法,不涉及回到不可空的int
或转换为float
?我已经确认这适用于旧的dtype dtype={'a': 'int'}
和dtype={'a': 'float'}
。
2条答案
按热度按时间pkmbmrz71#
实际上,即使您没有指定
thousands
参数,也会触发错误。这是一个开放的问题(* 参见 * GH52594)。在使用C
引擎调用read_csv
时,您还不能应用nullable dtype。一个简单的解决方法是使用
astype
:2skhul332#
默认引擎是
c
,您希望使用python
输出