pyspark.pandas.Series.align#

Series.align(other, join='outer', axis=None, copy=True)[source]#

Align two objects on their axes with the specified join method.

Join method is specified for each axis Index.

Parameters
otherDataFrame or Series
join{{‘outer’, ‘inner’, ‘left’, ‘right’}}, default ‘outer’
axisallowed axis of the other object, default None

Align on index (0), columns (1), or both (None).

copybool, default True

Always returns new objects. If copy=False and no reindexing is required then original objects are returned.

Returns
(left, right)(Series, type of other)

Aligned objects.

Examples

>>> ps.set_option("compute.ops_on_diff_frames", True)
>>> s1 = ps.Series([7, 8, 9], index=[10, 11, 12])
>>> s2 = ps.Series(["g", "h", "i"], index=[10, 20, 30])
>>> aligned_l, aligned_r = s1.align(s2)
>>> aligned_l.sort_index()
10    7.0
11    8.0
12    9.0
20    NaN
30    NaN
dtype: float64
>>> aligned_r.sort_index()
10       g
11    None
12    None
20       h
30       i
dtype: object

Align with the join type “inner”:

>>> aligned_l, aligned_r = s1.align(s2, join="inner")
>>> aligned_l.sort_index()
10    7
dtype: int64
>>> aligned_r.sort_index()
10    g
dtype: object

Align with a DataFrame:

>>> df = ps.DataFrame({"a": [1, 2, 3], "b": ["a", "b", "c"]}, index=[10, 20, 30])
>>> aligned_l, aligned_r = s1.align(df)
>>> aligned_l.sort_index()
10    7.0
11    8.0
12    9.0
20    NaN
30    NaN
dtype: float64
>>> aligned_r.sort_index()
      a     b
10  1.0     a
11  NaN  None
12  NaN  None
20  2.0     b
30  3.0     c
>>> ps.reset_option("compute.ops_on_diff_frames")