Why slicing Pandas column and then subtract gives NaN?

C W <[email protected]>
Newsgroups gmane.comp.python.scientific.user
Message-ID <CAE2FW2mARV2XRyxhMDtYiW45tc8nji8nrYLnQjNjPzc3DinejQ__25026.6626988136$1550098446$gmane$org@mail.gmail.com>
Dear list,

I have the following to Pandas Series: a, b. I want to slice and then
subtract. Like this: a[1:4] - b[0:3]. Why does it give me NaN? But it works
in Numpy.

Example 1: did not work
>>>a = pd.Series([85, 86, 87, 86])
>>>b = pd.Series([15, 72, 2, 3])
>>> a[1:4]-b[0:3] 0   NaN 1   14.0 2   85.0 3   NaN
>>> type(a[1:4])
<class 'pandas.core.series.Series'>

Example 2: worked
If I use values() method, it's converted to a Numpy object. And it works!
>>> a.values[1:4]-b.values[0:3]
array([71, 15, 84])
>>> type(a.values[1:4])
<class 'numpy.ndarray'>

What's the reason that Pandas in example 1 did not work? Isn't Numpy built
on top of Pandas? So, why is everything ok in Numpy, but not in Pandas?

Thanks in advance!

_______________________________________________
SciPy-User mailing list
[email protected]
https://mail.python.org/mailman/listinfo/scipy-user
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.