Table Of Contents

Search

Enter search terms or a module, class or function name.

pandas.api.types.is_sparse

pandas.api.types.is_sparse(arr)[source]

Check whether an array-like is a pandas sparse array.

Parameters:

arr : array-like

The array-like to check.

Returns:
boolean : Whether or not the array-like is a pandas sparse array.

Examples

>>> is_sparse(np.array([1, 2, 3]))
False
>>> is_sparse(pd.SparseArray([1, 2, 3]))
True
>>> is_sparse(pd.SparseSeries([1, 2, 3]))
True

This function checks only for pandas sparse array instances, so sparse arrays from other libraries will return False.

>>> from scipy.sparse import bsr_matrix
>>> is_sparse(bsr_matrix([1, 2, 3]))
False
Scroll To Top