pandas.DataFrame.sparse#

DataFrame.sparse()[source]#

DataFrame accessor for sparse data.

Parameters:
datascipy.sparse.spmatrix

Must be convertible to csc format.

See also

DataFrame.sparse.density

Ratio of non-sparse points to total (dense) data points.

Examples

>>> df = pd.DataFrame({"a": [1, 2, 0, 0], "b": [3, 0, 0, 4]}, dtype="Sparse[int]")
>>> df.sparse.density
0.5