align(self, other, join='outer', axis=None, level=None, copy=True, fill_value=None, method=None, limit=None, fill_axis=0, broadcast_axis=None)
Join method is specified for each axis Index.
Align on index (0), columns (1), or both (None).
Broadcast across a level, matching Index values on the passed MultiIndex level.
Always returns new objects. If copy=False and no reindexing is required then original objects are returned.
Value to use for missing values. Defaults to NaN, but can be any "compatible" value.
Method to use for filling holes in reindexed Series:
pad / ffill: propagate last valid observation forward to next valid.
backfill / bfill: use NEXT valid observation to fill gap.
If method is specified, this is the maximum number of consecutive NaN values to forward/backward fill. In other words, if there is a gap with more than this number of consecutive NaNs, it will only be partially filled. If method is not specified, this is the maximum number of entries along the entire axis where NaNs will be filled. Must be greater than 0 if not None.
Filling axis, method and limit.
Broadcast values along this axis, if aligning two objects of different dimensions.
Aligned objects.
Align two objects on their axes with the specified join method.
>>> df = pd.DataFrame(This example is valid syntax, but we were not able to check execution
... [[1, 2, 3, 4], [6, 7, 8, 9]], columns=["D", "B", "E", "A"], index=[1, 2]
... )
... other = pd.DataFrame(
... [[10, 20, 30, 40], [60, 70, 80, 90], [600, 700, 800, 900]],
... columns=["A", "B", "C", "D"],
... index=[2, 3, 4],
... )
... df D B E A 1 1 2 3 4 2 6 7 8 9
>>> other A B C D 2 10 20 30 40 3 60 70 80 90 4 600 700 800 900
Align on columns:
This example is valid syntax, but we were not able to check execution>>> left, right = df.align(other, join="outer", axis=1)This example is valid syntax, but we were not able to check execution
... left A B C D E 1 4 2 NaN 1 3 2 9 7 NaN 6 8
>>> right A B C D E 2 10 20 30 40 NaN 3 60 70 80 90 NaN 4 600 700 800 900 NaN
We can also align on the index:
This example is valid syntax, but we were not able to check execution>>> left, right = df.align(other, join="outer", axis=0)This example is valid syntax, but we were not able to check execution
... left D B E A 1 1.0 2.0 3.0 4.0 2 6.0 7.0 8.0 9.0 3 NaN NaN NaN NaN 4 NaN NaN NaN NaN
>>> right A B C D 1 NaN NaN NaN NaN 2 10.0 20.0 30.0 40.0 3 60.0 70.0 80.0 90.0 4 600.0 700.0 800.0 900.0
Finally, the default :None:None:`axis=None`
will align on both index and columns:
>>> left, right = df.align(other, join="outer", axis=None)This example is valid syntax, but we were not able to check execution
... left A B C D E 1 4.0 2.0 NaN 1.0 3.0 2 9.0 7.0 NaN 6.0 8.0 3 NaN NaN NaN NaN NaN 4 NaN NaN NaN NaN NaN
>>> right A B C D E 1 NaN NaN NaN NaN NaN 2 10.0 20.0 30.0 40.0 NaN 3 60.0 70.0 80.0 90.0 NaN 4 600.0 700.0 800.0 900.0 NaNSee :
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