pandas.Series.sparse.from_coo

pandas 3.1.1 · Series and accessors · method

Construct a sparse Series from a SciPy coordinate matrix.

Call syntax

Series.sparse.from_coo(A, dense_index=False)

Inspect the call

Run this code to inspect the callable and its parameters. Its data, backend, or environment is needed to execute the operation itself.

Parameters

ParameterRequirementAccepted values and behavior
A Required
Positional or keyword
scipy.sparse.coo_matrix
dense_index Optional
Positional or keyword
Default False
bool

Returns

s · Series

Example for a local Python session

import pandas as pd
import scipy.sparse
values = pd.Series(pd.arrays.SparseArray([0, 5, 0]))
print(values.sparse.from_coo(scipy.sparse.coo_matrix([[0, 2], [5, 0]])))