當我轉換numpy的陣列到大熊貓數據幀大熊貓改變UINT64類型的對象類型,如果整數大於2^63 - 1爲什麼熊貓將unsigned int大於2 ** 63-1轉換爲對象?
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')
這是惱人的,因爲我不能寫入數據幀到表格式的文件HDF:
pd.DataFrame(x).to_hdf('x.hdf', 'key', format = 'table')
輸出繼電器:
類型錯誤:無法序列列[無符號]因爲 它的數據內容是[整數]對象D型
有人可以解釋類型轉換嗎?
這是一個開放的bug:https://github.com/pydata/pandas/issues/11846#event-492663948 看到我的工作回答ound。 – imp9