pandas 1.4.2

AttributesMethodsParametersBackRef

Attributes

None :

Methods

Parameters

data : array-like or scalar

A dense array of values to store in the SparseArray. This may contain :None:None:`fill_value`.

sparse_index : SparseIndex, optional
index : Index
deprecated

Use a function like :None:None:`np.full` to construct an array with the desired repeats of the scalar value instead.

fill_value : scalar, optional

Elements in data that are fill_value are not stored in the SparseArray. For memory savings, this should be the most common value in :None:None:`data`. By default, :None:None:`fill_value` depends on the dtype of :None:None:`data`:

=========== ========== data.dtype na_value =========== ========== float np.nan int 0 bool False datetime64 pd.NaT timedelta64 pd.NaT =========== ==========

The fill value is potentially specified in three ways. In order of precedence, these are

  1. The :None:None:`fill_value` argument

  2. dtype.fill_value if :None:None:`fill_value` is None and dtype is a SparseDtype

  3. data.dtype.fill_value if :None:None:`fill_value` is None and dtype is not a SparseDtype and :None:None:`data` is a SparseArray .

kind : str

Can be 'integer' or 'block', default is 'integer'. The type of storage for sparse locations.

  • 'block': Stores a :None:None:`block` and :None:None:`block_length` for each contiguous span of sparse values. This is best when sparse data tends to be clumped together, with large regions of fill-value values between sparse values.

  • 'integer': uses an integer to store the location of each sparse value.

dtype : np.dtype or SparseDtype, optional

The dtype to use for the SparseArray. For numpy dtypes, this determines the dtype of self.sp_values . For SparseDtype, this determines self.sp_values and self.fill_value .

copy : bool, default False

Whether to explicitly copy the incoming :None:None:`data` array.

An ExtensionArray for storing sparse data.

Examples

This example is valid syntax, but we were not able to check execution
>>> from pandas.arrays import SparseArray
... arr = SparseArray([0, 0, 1, 2])
... arr [0, 0, 1, 2] Fill: 0 IntIndex Indices: array([2, 3], dtype=int32)
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas.core.arrays.sparse.array.SparseArray

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/core/arrays/sparse/array.py#284
type: <class 'type'>
Commit: