当我将numpy数组转换为pandas数据帧时,如果整数大于2 ^ 63 - 1,pandas会将uint64类型更改为对象类型.
import pandas as pd
import numpy as np
x = np.array([('foo', 2 ** 63)], dtype = np.dtype([('string', np.str_, 3), ('unsigned', np.uint64)]))
y = np.array([('foo', 2 ** 63 - 1)], dtype = np.dtype([('string', np.str_, 3), ('unsigned', np.uint64)]))
print pd.DataFrame(x).dtypes.unsigned
dtype('O')
print pd.DataFrame(y).dtypes.unsigned
dtype('uint64')
Run Code Online (Sandbox Code Playgroud)
这很烦人,因为我无法以表格格式将数据帧写入hdf文件:
pd.DataFrame(x).to_hdf('x.hdf', 'key', format = 'table')
Run Code Online (Sandbox Code Playgroud)
输出继电器:
TypeError:无法序列化[unsigned]列,因为其数据内容为[integer] object dtype
有人可以解释类型转换吗?