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