Python Pandas - 使用 0 個元素檢查索引是否為空
要檢查索引是否為空且包含 0 個元素,請在 Pandas 中使用 index.empty 屬性。
首先,匯入所需的庫 −
import pandas as pd
建立索引 −
index = pd.Index([])
顯示索引 −
print("Pandas Index...\n",index)檢查空索引 −
print("\nIs the index empty?\n",index.empty)
示例
以下是程式碼 −
import pandas as pd
# Creating the index
index = pd.Index([])
# Display the index
print("Pandas Index...\n",index)
# Return the number of elements in the Index
print("\nNumber of elements in the index...\n",index.size)
# check for empty index
print("\nIs the index empty?\n",index.empty)輸出
將生成以下程式碼 −
Pandas Index... Index([], dtype='object') Number of elements in the index... 0 Is the index empty? True
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP