Python Pandas - 返回索引的轉置
要返回索引的轉置,請使用 index.T 屬性。
首先,匯入所需的庫 −
import pandas as pd
建立索引 −
index = pd.Index(['Car','Bike','Truck','Ship','Airplane'])
顯示索引 −
print("Pandas Index...\n",index)
顯示索引的轉置 −
print("\nTranspose of the Pandas Index which is by definition self...\n",index.T)
示例
以下是程式碼 −
import pandas as pd # Creating the index index = pd.Index(['Car','Bike','Truck','Ship','Airplane']) # Display the index print("Pandas Index...\n",index) # Return an array representing the data in the Index print("\nArray...\n",index.values) # Display the transpose of the index print("\nTranspose of the Pandas Index which is by definition self...\n",index.T)
輸出
這會產生以下程式碼 −
Pandas Index... Index(['Car', 'Bike', 'Truck', 'Ship', 'Airplane'], dtype='object') Array... ['Car' 'Bike' 'Truck' 'Ship' 'Airplane'] Transpose of the Pandas Index which is by definition self... Index(['Car', 'Bike', 'Truck', 'Ship', 'Airplane'], dtype='object')
廣告