pandas.DataFrame.sparse#
- DataFrame.sparse()[source]#
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:
- 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