Python Pandas - 检查两个 Index 对象是否具有相似的对象属性和类型
要检查两个Index对象是否具有相似的对象属性和类型,请使用index1.identical(index2)方法。
首先,导入所需的库——
import pandas as pd
创建Pandasindex1和index2-
index1 = pd.Index([15, 25, 35, 45, 55]) index2 = pd.Index([15, 25, 35, 45, 55])
显示index1和index2-
print("Pandas Index1...\n",index1)
print("Pandas Index2...\n",index2)检查两个索引对象是否具有相似的属性和类型-
print("\nThe two Index objects have similar attributes and types?" "\n",index1.identical(index2))示例
以下是代码-
import pandas as pd
#创建Pandasindex1和index2
index1 = pd.Index([15, 25, 35, 45, 55])
index2 = pd.Index([15, 25, 35, 45, 55])
#显示index1和index2
print("Pandas Index1...\n",index1)
print("Pandas Index2...\n",index2)
print("\nThe two Index objects have similar attributes and types?" "\n",index1.identical(index2))输出结果这将产生以下输出-
Pandas Index1... Int64Index([15, 25, 35, 45, 55], dtype='int64') Pandas Index2... Int64Index([15, 25, 35, 45, 55], dtype='int64') The two Index objects have similar attributes and types? True
热门推荐
10 新人红包祝福语简短精辟
11 幼师给毕业祝福语简短
12 生日高考祝福语妹妹简短
13 下飞机祝福语简短英文
14 元宵发客户祝福语简短
15 爸妈金婚文案祝福语简短
16 新郎朋友红包祝福语简短
17 虎年五一祝福语大全简短
18 出阁宴祝福语姐姐简短