要返回索引中的所有元素是否都为 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
# 创建索引
index = pd.index([15, 25, 35, 45, 55])
# 显示索引
print("pandas index...\n",index)
# 返回基础数据形状的元组
print("\na tuple of the shape of underlying data...\n",index.shape)
# 返回索引中的元素数
print("\nnumber of elements in the index...\n",index.size)
# 如果索引中的所有元素都为 true,则返回 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