Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.DataFrame.sparse.to_coo#

DataFrame.sparse.to_coo()[source]#

Return the contents of the frame as a sparse SciPy COO matrix.

Returns:
scipy.sparse.spmatrix

If the caller is heterogeneous and contains booleans or objects,the result will be of dtype=object. See Notes.

Notes

The dtype will be the lowest-common-denominator type (implicitupcasting); that is to say if the dtypes (even of numeric types)are mixed, the one that accommodates all will be chosen.

e.g. If the dtypes are float16 and float32, dtype will be upcast tofloat32. By numpy.find_common_type convention, mixing int64 andand uint64 will result in a float64 dtype.

Examples

>>>df=pd.DataFrame({"A":pd.arrays.SparseArray([0,1,0,1])})>>>df.sparse.to_coo()<COOrdinate sparse matrix of dtype 'int64'    with 2 stored elements and shape (4, 1)>

[8]ページ先頭

©2009-2025 Movatter.jp