class_docstr: 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
class_docstr_tok: ["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"]
docstr: Create a new DataFrame from a scipy sparse matrix.
  
  Parameters
  ----------
  data : scipy.sparse.spmatrix
      Must be convertible to csc format.
  index, columns : Index, optional
      Row and column labels to use for the resulting DataFrame.
      Defaults to a RangeIndex.
  
  Returns
  -------
  DataFrame
      Each column of the DataFrame is stored as a
      :class:`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
docstr_tok: ["Create","a","new","DataFrame","from","a","scipy","sparse","matrix",".","Parameters","--","--","--","--","--","data",":","scipy.sparse.spmatrix","Must","be","convertible","to","csc","format",".","index",",","columns",":","Index",",","optional","Row","and","column","labels","to","use","for","the","resulting","DataFrame",".","Defaults","to","a","RangeIndex",".","Returns","--","--","--","-","DataFrame","Each","column","of","the","DataFrame","is","stored","as","a",":","class",":","`","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"]
code: def from_spmatrix(cls, data, index=None, columns=None) -> DataFrame:
      """
      Create a new DataFrame from a scipy sparse matrix.
  
      Parameters
      ----------
      data : scipy.sparse.spmatrix
          Must be convertible to csc format.
      index, columns : Index, optional
          Row and column labels to use for the resulting DataFrame.
          Defaults to a RangeIndex.
  
      Returns
      -------
      DataFrame
          Each column of the DataFrame is stored as a
          :class:`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
      """
      from pandas._libs.sparse import IntIndex
  
      from pandas import DataFrame
  
      data = data.tocsc()
      index, columns = cls._prep_index(data, index, columns)
      n_rows, n_columns = data.shape
      # We need to make sure indices are sorted, as we create
      # IntIndex with no input validation (i.e. check_integrity=False ).
      # Indices may already be sorted in scipy in which case this adds
      # a small overhead.
      data.sort_indices()
      indices = data.indices
      indptr = data.indptr
      array_data = data.data
      dtype = SparseDtype(array_data.dtype, 0)
      arrays = []
      for i in range(n_columns):
          sl = slice(indptr[i], indptr[i + 1])
          idx = IntIndex(n_rows, indices[sl], check_integrity=False)
          arr = SparseArray._simple_new(array_data[sl], idx, dtype)
          arrays.append(arr)
      return DataFrame._from_arrays(
          arrays, columns=columns, index=index, verify_integrity=False
      )
  
imports: from __future__ import annotations
  from typing import TYPE_CHECKING
  import numpy
  from pandas.compat._optional import import_optional_dependency
  from pandas.core.dtypes.cast import find_common_type
  from pandas.core.dtypes.dtypes import SparseDtype
  from pandas.core.accessor import PandasDelegate, delegate_names
  from pandas.core.arrays.sparse.array import SparseArray
label_desc: Use image node_id 2 for calling the SparseFrameAccessor obj's underlying member method code with example usage: obj.from_spmatrix(cls, data, index, columns) and returns: DataFrame