Skip to main content
`Ctrl`+`K`

# pandas.DataFrame.sparse

DataFrame.sparse()

  DataFrame accessor for sparse data.

  It allows users to interact with a DataFrame that contains sparse data types (SparseDtype). It provides methods and attributes to efficiently work with sparse storage, reducing memory usage while maintaining compatibility with standard pandas operations.

  Parameters:
    data scipy.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
      np.float64(0.5)