pandas.Series.sparse.from_coo #
- 类方法 Series.sparse。from_coo ( A , dense_index = False ) [来源] #
使用 scipy.sparse.coo_matrix 中的稀疏值创建一个系列。
- 参数:
- scipy.sparse.coo_matrix
- ensemble_index布尔值,默认 False
如果为 False(默认值),则索引仅包含原始 coo_matrix 的非空条目的坐标。如果为 True,则索引由 coo_matrix 的完整排序(行、列)坐标组成。
- 返回:
- S系列
具有稀疏值的系列。
例子
>>> from scipy import sparse
>>> A = sparse.coo_matrix( ... ([3.0, 1.0, 2.0], ([1, 0, 0], [0, 2, 3])), shape=(3, 4) ... ) >>> A <3x4 sparse matrix of type '<class 'numpy.float64'>' with 3 stored elements in COOrdinate format>
>>> 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]