pandas.DataFrame.sparse

DataFrame.sparse()[source]

DataFrame accessor for sparse data.

Examples

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

© 2008–2011, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
© 2011–2025, Open source contributors
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/2.3.0/reference/api/pandas.DataFrame.sparse.html