Skip to main content
`Ctrl`+`K`

# pandas.DataFrame.sparse.density

DataFrame.sparse.density

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

  This property returns the proportion of the data that is not sparse (i.e., not equal to the fill value), as a value between 0 and 1.

  See also

  `DataFrame.sparse.from_spmatrix`

    Create a new DataFrame from a scipy sparse matrix.

  Examples

      >>> df = pd.DataFrame({"A": pd.arrays.SparseArray([0, 1, 0, 1])})
      >>> df.sparse.density
      np.float64(0.5)