pandas.SparseDtype#

class pandas.SparseDtype(dtype=<class 'numpy.float64'>, fill_value=None)[源代码]#

存储在 SparseArray 中的数据的 Dtype。

此 dtype 实现 pandas 扩展 Dtype 接口。

Parameters:
dtypestr、ExtensionDtype、numpy.dtype、type,默认为 numpy.float64

存储非填充值的底层数组的数据类型。

fill_valuescalar, optional

未存储在 SparseArray 中的标量值。默认情况下,这取决于 dtype

dtype

na_value

float

np.nan

int

0

bool

False

datetime64

pd.NaT

timedelta64

pd.NaT

默认值可以通过指定 fill_value 来覆盖。

Examples

>>> ser = pd.Series([1, 0, 0], dtype=pd.SparseDtype(dtype=int, fill_value=0))
>>> ser
0    1
1    0
2    0
dtype: Sparse[int64, 0]
>>> ser.sparse.density
0.3333333333333333

Attributes

None

Methods

None