import pandas as pd
import numpy as np
index = [('California', 2000), ('California', 2010),
('New York', 2000), ('New York', 2010),
('Texas', 2000), ('Texas', 2010)]
populations = [33871648, 37253956,
18976457, 19378102,
20851820, 25145561]
pop = pd.Series(populations, index=index)
index = pd.MultiIndex.from_tuples(index)
pop = pop.reindex(index)
d1 = pop.loc['California':'New York']
d2 = pop['California':'New York']
print(d1)
print(d2)
print(d1 is d2)
'''我不理解d1和d2显示相同的结果,但是为什么它们不同?最后的结果显示为“ False”''
答案 0 :(得分:0)
python is
运算符检查两个参数是否是同一对象,而不是equal
。您可以查看示例
print(id(d1) is id(d2))
将返回false,因为即使d1和d1相同,但它们本质上是克隆。