pandas.Index.to_flat_index#
- Index.to_flat_index()[source]#
Return the Index unchanged, since it is already flat.
An
Indexhas a single level, so there is nothing to flatten. This method exists so that code can callto_flat_indexon any index, for example ondf.columns, without checking whether it is aMultiIndexfirst.- Returns:
- Index
The caller itself, not a copy.
See also
MultiIndex.to_flat_indexConvert a MultiIndex to an Index of tuples.
Examples
>>> idx = pd.Index(["a", "b", "c"]) >>> idx.to_flat_index() Index(['a', 'b', 'c'], dtype='str')
The same call works on a
MultiIndex, where it flattens the levels into tuples:>>> mi = pd.MultiIndex.from_arrays([["a", "b"], [1, 2]]) >>> mi.to_flat_index() Index([('a', 1), ('b', 2)], dtype='object')