Python Pandas:返回底層資料型別的 dtype 物件
若要返回底層資料的 dtype 物件,請在 Pandas 中使用 index.dtype 屬性。
首先,匯入所需的庫-
import pandas as pd
建立索引-
index = pd.Index(['Car','Bike', 'Shop','Car','Airplace', 'Truck'])
顯示索引-
print("Pandas Index...\n",index)返回資料的 dtype-
print("\nThe dtype object...\n",index.dtype)
示例
以下是程式碼-
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)輸出
這將生成以下程式碼-
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,)
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP