pandas.Series.sparse.from_coo#
- classmethod Series.sparse.from_coo(A, dense_index=False)[源代码]#
从 scipy.sparse.coo_matrix 创建一个具有稀疏值的 Series。
- Parameters:
- Ascipy.sparse.coo_matrix
- dense_indexbool,默认 False
如果为 False(默认值),索引仅包含原始 coo_matrix 的非空条目的坐标。如果为 True,索引包含 coo_matrix 的完整排序的(行,列)坐标。
- Returns:
- sSeries
具有稀疏值的 Series。
Examples
>>> from scipy import sparse
>>> A = sparse.coo_matrix( ... ([3.0, 1.0, 2.0], ([1, 0, 0], [0, 2, 3])), shape=(3, 4) ... ) >>> A <COOrdinate sparse matrix of dtype 'float64' with 3 stored elements and shape (3, 4)>
>>> A.todense() matrix([[0., 0., 1., 2.], [3., 0., 0., 0.], [0., 0., 0., 0.]])
>>> ss = pd.Series.sparse.from_coo(A) >>> ss 0 2 1.0 3 2.0 1 0 3.0 dtype: Sparse[float64, nan]