Dtype for data stored in SparseArray.
This dtype implements the pandas ExtensionDtype interface.
The dtype of the underlying array storing the non-fill value values.
The scalar value not stored in the SparseArray. By default, this depends on dtype.
dtype | na_value |
|---|---|
float |
|
int |
|
bool |
|
datetime64 |
|
timedelta64 |
|
The default value may be overridden by specifying a fill_value.
Attributes
None |
Methods
None |
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
© 2008–2011, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
© 2011–2025, Open source contributors
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/2.3.0/reference/api/pandas.SparseDtype.html