ในการส่งคืน Transpose ของดัชนี ให้ใช้ 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')