- API reference
- Series
- pandas.Serie...
pandas.Series.sparse.from_coo#
- classmethodSeries.sparse.from_coo(A,dense_index=False)[source]#
Create a Series with sparse values from a scipy.sparse.coo_matrix.
- Parameters:
- Ascipy.sparse.coo_matrix
- dense_indexbool, default False
If False (default), the index consists of only thecoords of the non-null entries of the original coo_matrix.If True, the index consists of the full sorted(row, col) coordinates of the coo_matrix.
- Returns:
- sSeries
A Series with sparse values.
Examples
>>>fromscipyimportsparse
>>>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)>>>ss0 2 1.0 3 2.01 0 3.0dtype: Sparse[float64, nan]
On this page