Python - 檢查 Pandas 索引是否是物件資料型別
如需檢查 Pandas 索引是否是物件資料型別,請使用 index.is_object() 方法。首先,匯入所需的庫 -
import pandas as pd
建立 Pandas 索引 -
index = pd.Index(["Electronics", 6, 10.5, "Accessories", 25.6, 30])
顯示 Pandas 索引 -
print("Pandas Index...\n",index)檢查索引值是否為物件資料型別 -
print("\nIs the Index of object dtype?\n", index.is_object())
示例
以下為程式碼 -
import pandas as pd
# Creating Pandas index
index = pd.Index(["Electronics", 6, 10.5, "Accessories", 25.6, 30])
# Display the Pandas index
print("Pandas Index...\n",index)
# Return the number of elements in the Index
print("\nNumber of elements in the index...\n",index.size)
# Return the dtype of the data
print("\nThe dtype object...\n",index.dtype)
# check whether index values has object dtype
print("\nIs the Index of object dtype?\n", index.is_object())輸出
這會產生以下輸出 -
Pandas Index... Index(['Electronics', 6, 10.5, 'Accessories', 25.6, 30], dtype='object') Number of elements in the index... 6 The dtype object... object Is the Index of object dtype? True
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP