Để trả về đối tượng dtype của dữ liệu cơ bản, hãy sử dụng index.dtype 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', 'Shop','Car','Airplace', 'Truck'])
Hiển thị chỉ mục -
print("Pandas Index...\n",index) Trả về loại dữ liệu -
print("\nThe dtype object...\n",index.dtype)
Ví dụ
Sau đây là mã -
import pandas as pd
# Creating the index
index = pd.Index(['Car','Bike', 'Shop','Car','Airplace', 'Truck'])
# Display the index
print("Pandas Index...\n",index)
# Return an array representing the data in the Index
print("\nArray...\n",index.values)
# Return the dtype of the data
print("\nThe dtype object...\n",index.dtype)
# 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', 'Shop', 'Car', 'Airplace', 'Truck'], dtype='object') Array... ['Car' 'Bike' 'Shop' 'Car' 'Airplace' 'Truck'] The dtype object... object A tuple of the shape of underlying data... (6,)