classmethod sparse.from_spmatrix(data, index=None, columns=None) Create a new DataFrame from a scipy sparse matrix.
New in version 0.25.0.
| Parameters: |
|
|---|---|
| Returns: |
|
>>> import scipy.sparse
>>> mat = scipy.sparse.eye(3)
>>> pd.DataFrame.sparse.from_spmatrix(mat)
0 1 2
0 1.0 0.0 0.0
1 0.0 1.0 0.0
2 0.0 0.0 1.0
© 2008–2012, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/0.25.0/reference/api/pandas.DataFrame.sparse.from_spmatrix.html