หากต้องการคืนค่าทูเพิลของรูปร่างของข้อมูลพื้นฐาน ให้ใช้ index.shape ทรัพย์สินในหมีแพนด้า
ขั้นแรก นำเข้าไลบรารีที่จำเป็น -
import pandas as pd
การสร้างดัชนี -
index = pd.Index(['Car','Bike','Truck','Car','Airplane'])
แสดงดัชนี -
print("Pandas Index...\n",index) ส่งกลับทูเพิลของรูปร่างของข้อมูลพื้นฐาน -
print("\nA tuple of the shape of underlying data...\n",index.shape)
ตัวอย่าง
ต่อไปนี้เป็นรหัส -
import pandas as pd
# Creating the index
index = pd.Index(['Car','Bike','Truck','Car','Airplane'])
# Display the index
print("Pandas Index...\n",index)
# Return an array representing the data in the Index
print("\nArray...\n",index.values)
# Return a tuple of the shape of the underlying data
print("\nA tuple of the shape of underlying data...\n",index.shape) ผลลัพธ์
สิ่งนี้จะสร้างรหัสต่อไปนี้ -
Pandas Index... Index(['Car', 'Bike', 'Truck', 'Car', 'Airplane'], dtype='object') Array... ['Car' 'Bike' 'Truck' 'Car' 'Airplane'] A tuple of the shape of underlying data... (5,)