Skip to main content
`Ctrl`+`K`

# pandas.Series.sparse

Series.sparse()

  Accessor for SparseSparse from other sparse matrix data types.

  Provides methods and properties to work with the underlying sparse data in a Series or DataFrame. It allows accessing sparse-specific attributes such as fill value, density, and stored non-fill values, as well as converting to and from scipy sparse matrices.

  Parameters:
    data Series or DataFrame

      The Series or DataFrame to which the SparseAccessor is attached.

  See also

  `Series.sparse.to_coo`

    Create a scipy.sparse.coo_matrix from a Series with MultiIndex.

  `Series.sparse.from_coo`

    Create a Series with sparse values from a scipy.sparse.coo_matrix.

  Examples

      >>> ser = pd.Series([0, 0, 2, 2, 2], dtype="Sparse[int]")
      >>> ser.sparse.density
      0.6
      >>> ser.sparse.sp_values
      array([2, 2, 2])