Python 多層索引1之from_frame簡介

 

python多層索引的含義這裏就不再介紹了。

這裏主要介紹幾種應用:如何通過數組、元組、卡迪爾積創建多層索引以及如何將多層索引作爲一個整體,對其內部進行索引。

通過數組、元組、卡迪爾積創建多層索引需要使用如下四個函數:pandas.MultiIndex.from_frame

pandas.MultiIndex.from_arrays

pandas.MultiIndex.from_tuple和

pandas.MultiIndex.from_product

首先介紹pandas.MultiIndex.from_frame,就是將pandas的frame變爲多層索引。它有三個參數:

pandas.MultiIndex.from_frame(df, sortorder=None, names=None)

df:frame數組

sortorder:排序順序,可選參數。

名稱:設置多層索引名稱,可選。默認採用df列的名稱。示例如下

index_t爲想要設置爲索引的dataframe

 

df爲需要的dataframe

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章