以下代码:
import numpy as np
import pandas as pd
data = pd.DataFrame(np.random.randn(3), index=[[(2015, 8, 16), (2015, 8, 17), (2015, 8, 17)]])
print(data)
print((99,99,99) in data.index)
产生意外行为:
0
2015 8 16 1.496188
17 1.766312
17 1.487920
True
我做错了什么?如何正确检查分层索引?
顺便说一句,奇怪的是这段代码:
for x in data.index:
print(x == (99,99,99))
print(x == (2015,8,16))
做正确的事:
False
True
False
False
False
False
虽然显然不可取。