Python Pandas - 返回索引中的所有元素是否均为 True
要返回索引中的所有元素是否都为 True,请在 Pandas 中使用 index.all() 方法。
首先,导入所需的库 −
import pandas as pd
创建索引 −
index = pd.Index([15, 25, 35, 45, 55])
显示索引 −
print("Pandas Index...\n",index)如果索引中的所有元素都为 True 则返回 True −
print("\nCheck whether all elements are True...\n",index.all())
示例
以下是代码 −
import pandas as pd
# Creating the index
index = pd.Index([15, 25, 35, 45, 55])
# Display the index
print("Pandas Index...\n",index)
# Return a tuple of the shape of the underlying data
print("\nA tuple of the shape of underlying data...\n",index.shape)
# Return the number of elements in the Index
print("\nNumber of elements in the index...\n",index.size)
# Return True if all the elements in the index are True
print("\nCheck whether all elements are True...\n",index.all())输出
这将生成以下代码 −
Pandas Index... Int64Index([15, 25, 35, 45, 55], dtype='int64') A tuple of the shape of underlying data... (5,) Number of elements in the index... 5 Check whether all elements are True... True
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP