【发布时间】:2016-10-31 21:00:04
【问题描述】:
请尝试了解以下 read_csv 行为的原因: 我正在尝试分块读取一个大文件
c=1
for chunk in pd.read_csv(filename, chunksize=chunksize):
print 'chunk ', str(c), ' started'
....data normalization....
....saving the transformed data to file....
我收到这样的错误:
sys:1: DtypeWarning: Columns (...) have mixed types. Specify dtype option on import or set low_memory=False.
chunk 19 started
Traceback (most recent call last):
...
TypeError: unsupported operand type(s) for -: 'str' and 'float'
从我可以看到的错误中,出于某种原因,在块 19 pandas 将浮点数据解释为字符串,并且无法执行“-”操作。
但是,如果我跳过 18 个块,并从第 19 个块开始,它会顺利进行。 直觉说这可能是一些记忆问题,但我想了解原因。
【问题讨论】:
-
你试过“指定[ing] dtype选项吗?”
-
例如` dtype = {‘col1’: np.float64, ‘col2: np.int32}`