larray.LArray.reindex¶
-
LArray.reindex(axes_to_reindex=None, new_axis=None, fill_value=nan, inplace=False, **kwargs)[source]¶ Reorder and/or add new labels in axes.
Place NaN or given fill_value in locations having no value previously.
Parameters: axes_to_reindex : axis ref or dict {axis ref: axis} or list of tuple (axis ref, axis) or list of Axis or AxisCollection
Axes to reindex. If a single axis reference is given, the new_axis argument must be provided. If a list of Axis or an AxisCollection is given, all axes will be reindexed by the new ones. In that case, the number of new axes must match the number of the old ones.
new_axis : int, str, list/tuple/array of str or Axis, optional
List of new labels or new axis if axes_to_replace contains a single axis reference.
fill_value : scalar or LArray, optional
Value used to fill cells corresponding to label combinations which were not present before reindexing. Defaults to NaN.
inplace : bool, optional
Whether or not to modify the original object or return a new array and leave the original intact. Defaults to False.
**kwargs : Axis
New axis for each axis to reindex given as a keyword argument.
Returns: LArray
Array with reindexed axes.
Notes
When introducing NAs into an array containing integers via reindex, all data will be promoted to float in order to store the NAs.
Examples
>>> arr = ndtest((2, 2)) >>> arr a\b b0 b1 a0 0 1 a1 2 3
Reindex one axis
>>> arr.reindex(X.b, ['b1', 'b2', 'b0'], fill_value=-1) a\b b1 b2 b0 a0 1 -1 0 a1 3 -1 2 >>> arr.reindex(X.b, 'b0..b2', fill_value=-1) a\b b0 b1 b2 a0 0 1 -1 a1 2 3 -1
Reindex several axes
>>> a = Axis(['a1', 'a2', 'a0'], 'a') >>> b = Axis(['b2', 'b1', 'b0'], 'b') >>> arr.reindex({'a': a, 'b': b}, fill_value=-1) a\b b2 b1 b0 a1 -1 3 2 a2 -1 -1 -1 a0 -1 1 0 >>> arr.reindex({X.a: a, X.b: b}) a\b b2 b1 b0 a1 nan 3.0 2.0 a2 nan nan nan a0 nan 1.0 0.0
Reindex using axes from another array
>>> arr2 = ndrange('a=a0,a1;c=c0..c0;b=b0..b2') >>> arr2 a c\b b0 b1 b2 a0 c0 0 1 2 a1 c0 3 4 5 >>> arr.reindex(arr2.axes) a b\c c0 a0 b0 0.0 a0 b1 1.0 a0 b2 nan a1 b0 2.0 a1 b1 3.0 a1 b2 nan >>> arr2.reindex(arr.axes) a c\b b0 b1 a0 c0 0.0 1.0 a1 c0 3.0 4.0