问题
I'm trying to save a large sparse dataframe to a hdf5 file but I'm getting a attribution error:
one_hot = pd.get_dummies(my_DF, columns=['cat'], sparse=True)
one_hot.to_hdf('/content/data.h5', 'table', mode='w', append=True, complevel=9, complib='bzip2')
I get error:
AttributeError: 'SparseDtype' object has no attribute 'itemsize'
I have tried different combo's for to_hdf but no success. I have never converted to hdf5 before so I might be missing something. I couldn't find anything about this error on google so I'm wonder what is causing this error? and what can I do to fix it?
回答1:
https://github.com/pandas-dev/pandas/issues/31199 to_hdf does not support sparse data types as yet.
The good news is it's known but the bad news is it is not assigned to anyone and no fixes have been put in.
来源:https://stackoverflow.com/questions/65462891/getting-sparsedtype-object-has-no-attribute-itemsize-when-trying-to-save-spa