Để trả về nhiều hình dạng của dữ liệu cơ bản, hãy sử dụng index.shape tài sản ở Pandas.
Đầu tiên, hãy nhập các thư viện được yêu cầu -
import pandas as pd
Tạo chỉ mục -
index = pd.Index(['Car','Bike','Truck','Car','Airplane'])
Hiển thị chỉ mục -
print("Pandas Index...\n",index) Trả lại một loạt dữ liệu cơ bản -
print("\nA tuple of the shape of underlying data...\n",index.shape)
Ví dụ
Sau đây là mã -
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) Đầu ra
Điều này sẽ tạo ra mã sau -
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,)