pandas.MultiIndex.from_tuples#
- classmethod MultiIndex.from_tuples(tuples, sortorder=None, names=None)[源代码]#
将元组列表转换为 MultiIndex。
- Parameters:
- tupleslist / sequence of tuple-likes
每个元组是一个行/列的索引。
- sortorderint 或 None
排序级别(必须按该级别进行词典排序)。
- nameslist / sequence of str, optional
索引中层的名称。
- Returns:
- MultiIndex
参见
MultiIndex.from_arrays将数组列表转换为 MultiIndex。
MultiIndex.from_product从可迭代对象的笛卡尔积创建 MultiIndex。
MultiIndex.from_frame从 DataFrame 创建 MultiIndex。
Examples
>>> tuples = [(1, 'red'), (1, 'blue'), ... (2, 'red'), (2, 'blue')] >>> pd.MultiIndex.from_tuples(tuples, names=('number', 'color')) MultiIndex([(1, 'red'), (1, 'blue'), (2, 'red'), (2, 'blue')], names=['number', 'color'])