Series in Arkouda¶
Like Pandas, Arkouda supports Series. The purpose and intended functionality remains the same in Arkouda, but are configured to be based on arkouda.pdarrays.
- class arkouda.Series(data, name=None, index=None)[source]
One-dimensional Arkouda array with axis labels.
- Parameters:
index (
Union[pdarray,Strings,Tuple,List,Index,None]) – An array of indices associated with the data array. If not provided (or empty), it defaults to a range of ints whose size matches the size of the data.data (
Union[Tuple,List,pdarray,TypeVar(Strings),Categorical,Series,SegArray,Series,Categorical]) – A 1D array-like. Must not be None.
- Raises:
TypeError – Raised if
indexis not a pdarray or Strings object. Raised ifdatais not a supported type.ValueError – Raised if the index size does not match the data size.
Notes
The Series class accepts either positional arguments or keyword arguments.
- Positional arguments
Series(data):datais provided and an index is generated automatically.Series(data, index): bothdataandindexare provided.
- Keyword arguments
Series(data=..., index=...):indexis optional but must match the size ofdatawhen provided.
Features¶
Series support the majority of functionality offered by pandas.Series.
Lookup¶
- arkouda.Series.locate(self, key)
Lookup values by index label.
- Parameters:
key (
Union[int,pdarray,Index,Series,List,Tuple]) –The key or keys to look up. This can be: - A scalar - A list of scalars - A list of lists (for MultiIndex) - A Series (in which case labels are preserved, and its values are used as keys)
Keys will be converted to Arkouda arrays as needed.
- Returns:
A Series containing the values corresponding to the key.
- Return type:
Lookup¶
- arkouda.Series.locate(self, key)
Lookup values by index label.
- Parameters:
key (
Union[int,pdarray,Index,Series,List,Tuple]) –The key or keys to look up. This can be: - A scalar - A list of scalars - A list of lists (for MultiIndex) - A Series (in which case labels are preserved, and its values are used as keys)
Keys will be converted to Arkouda arrays as needed.
- Returns:
A Series containing the values corresponding to the key.
- Return type:
Sorting¶
- arkouda.Series.sort_index(self, ascending=True)
Sort the Series by its index.
- Parameters:
ascending (
bool) – Whether to sort the index in ascending (default) or descending order. Defaults to True.- Returns:
A new Series sorted by index.
- Return type:
- arkouda.Series.sort_values(self, ascending=True)
Sort the Series by its values.
- Parameters:
ascending (
bool) – Whether to sort values in ascending (default) or descending order. Defaults to True.- Returns:
A new Series sorted by its values.
- Return type:
Head/Tail¶
- arkouda.Series.topn(self, n=10)
Return the top values of the Series.
- Parameters:
n (
int) – Number of values to return. Defaults to 10.- Returns:
A new Series containing the top n values.
- Return type:
- arkouda.Series.head(self, n=10)
Return the first n values of the series.
- Return type:
- arkouda.Series.tail(self, n=10)
Return the last n values of the series.
- Return type:
Value Counts¶
- arkouda.Series.value_counts(self, sort=True)
Return a Series containing counts of unique values.
- Parameters:
sort (
bool) – Whether to sort the result by count in descending order. If False, the order of the results is not guaranteed. Defaults to True.- Returns:
A Series where the index contains the unique values and the values are their counts in the original Series.
- Return type:
Pandas Integration¶
- arkouda.Series.to_pandas(self)
Convert the series to a local PANDAS series.
- Return type:
Series
- arkouda.Series.pdconcat(arrays, axis=0, labels=None)
Concatenate a list of Arkouda Series or grouped arrays, returning a local pandas object.
If a list of grouped Arkouda arrays is passed, they are converted to Series. Each grouping is a 2-tuple with the first item being the key(s) and the second the value.
If axis=1 (horizontal), each Series or grouping must have the same length and the same index. The index is converted to a column in the resulting DataFrame. If it is a MultiIndex, each level is converted to a separate column.
- Parameters:
arrays (
List) – A list of Series or groupings (tuples of index and values) to concatenate.axis (
int) – The axis along which to concatenate: - 0 = vertical (stack into a Series) - 1 = horizontal (align by index into a DataFrame) Defaults to 0.labels (
Optional[Strings]) – Names to assign to the resulting columns in the DataFrame.
- Returns:
If axis=0: a local pandas Series
If axis=1: a local pandas DataFrame
- Return type:
Union[Series,DataFrame]