Create a new DataFrame from a scipy sparse matrix.
Must be convertible to csc format.
Row and column labels to use for the resulting DataFrame. Defaults to a RangeIndex.
Each column of the DataFrame is stored as a arrays.SparseArray.
Examples
>>> import scipy.sparse
>>> mat = scipy.sparse.eye(3, dtype=float)
>>> pd.DataFrame.sparse.from_spmatrix(mat)
0 1 2
0 1.0 0 0
1 0 1.0 0
2 0 0 1.0
© 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.from_spmatrix.html