2.12 Aliasing Axis Names
To globally provide aliases for axis names, one can define these 2 functions:
In [1]: def set_axis_alias(cls, axis, alias):
...: if axis not in cls._AXIS_NUMBERS:
...: raise Exception("invalid axis [%s] for alias [%s]" % (axis, alias))
...: cls._AXIS_ALIASES[alias] = axis
...:
In [2]: def clear_axis_alias(cls, axis, alias):
...: if axis not in cls._AXIS_NUMBERS:
...: raise Exception("invalid axis [%s] for alias [%s]" % (axis, alias))
...: cls._AXIS_ALIASES.pop(alias,None)
...:
In [3]: set_axis_alias(pd.DataFrame,'columns', 'myaxis2')
In [4]: df2 = pd.DataFrame(np.random.randn(3,2),columns=['c1','c2'],index=['i1','i2','i3'])
In [5]: df2.sum(axis='myaxis2')
Out[5]:
i1 0.186249
i2 -2.644691
i3 1.038897
dtype: float64
In [6]: clear_axis_alias(pd.DataFrame,'columns', 'myaxis2')