pandas.DataFrame.sparse.to_coo#
- DataFrame.sparse.to_coo()[源代码]#
以稀疏 SciPy COO 矩阵的形式返回 DataFrame 的内容。
- Returns:
- scipy.sparse.spmatrix
如果调用者是异构的并且包含布尔值或对象,则结果的 dtype 将为 object。请参阅 Notes。
Notes
dtype 将是最低公共分母类型(隐式向上转型);也就是说,如果 dtype(即使是数值类型)是混合的,将选择能够容纳所有类型的那个。
例如:如果 dtype 是 float16 和 float32,dtype 将向上转型为 float32。根据 numpy.find_common_type 的约定,int64 和 uint64 的混合将导致 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)>