I am using the python shift function to compare if a value in a Series is equal to the previus value. Basically
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
This is as expected. (The first comparison is False because we are comparing with the NA
of the shifted series). Now, I do have Series where I don't have any value, ie. None
, like this
b = pd.Series([None, None, 4, 5])
Here the comparison of the two None
s gives False
b == b.shift()
Out[3]:
0 False
1 False
2 False
3 False
dtype: bool
I'd be willing to accept some sort of philosophical reasoning arguing that comparing None
is meaningless etc., however
c = None
d = None
c == d
Out[4]: True
What is going on here?!
And, what I really want to know is; how can I perform my comparison of my b
-Series, given that I want it to treat None
's as equal? That is I want b == b.shift()
to give the same result as a == a.shift()
gave.