Start: Stop the mismatch between numpy and Pandas?

I am a bit surprised / confused about the following difference between numpy and Pandas

import numpy as np
import pandas as pd
a = np.random.randn(10,10)

> a[:3,0, newaxis]

array([[-1.91687144],
       [-0.6399471 ],
       [-0.10005721]])

However:

b = pd.DataFrame(a)

> b.ix[:3,0]

0   -1.916871
1   -0.639947
2   -0.100057
3    0.251988

In other words, numpy does not include the index stopin the notation start:stop, but Pandas does. I thought Pandas is based on Numpy. This is mistake? Intentional?

+5
source share
3 answers

This is documented and it is part of Advanced Indexing . The key point here is that you do not use the stop index at all.

ix - , - , .

, :

In [191]: b[:3][0]
Out[191]: 
0   -0.209386
1    0.050345
2    0.318414
Name: 0

, , , , , , , 'A', 'B', 'C', 'D' 0, 1, 2, 3, b.ix[:3] 3 4, .

, b.ix[:3] , .

, , " 3" " , 3", ix ( , t , ix ). , , .

+3
+2

(docs):

Python

...

, .

+1

All Articles