pandas.Series.sparse.density#

Series.sparse.density[source]#

The percent of non- fill_value points, as decimal.

This is calculated as the number of non-fill-value points divided by the total length of the array. A density of 1.0 means no values are the fill value, while 0.0 means all values are the fill value. An empty array has no density and returns nan.

See also

DataFrame.sparse.from_spmatrix

Create a new DataFrame from a scipy sparse matrix.

Examples

>>> from pandas.arrays import SparseArray
>>> s = SparseArray([0, 0, 1, 1, 1], fill_value=0)
>>> s.density
0.6