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 教师闺蜜祝福语简短