【发布时间】:2018-01-26 00:32:19
【问题描述】:
我正在使用 python shift 函数来比较 Series 中的值是否等于先前的值。基本上
import pandas as pd
a = pd.Series([2, 2, 4, 5])
a == a.shift()
Out[1]:
0 False
1 True
2 False
3 False
dtype: bool
这符合预期。 (第一个比较是 False,因为我们正在与移位系列的NA 进行比较)。现在,我确实有我没有任何价值的系列,即。 None,像这样
b = pd.Series([None, None, 4, 5])
这里两个Nones的比较得到False
b == b.shift()
Out[3]:
0 False
1 False
2 False
3 False
dtype: bool
我愿意接受某种哲学推理,认为比较 None 是没有意义的等等,但是
c = None
d = None
c == d
Out[4]: True
这是怎么回事?!
而且,我真正想知道的是;鉴于我希望它将None 视为平等,我如何对我的b 系列进行比较?那就是我希望b == b.shift() 给出与a == a.shift() 相同的结果。
【问题讨论】: