Skip to content

Why how is [] different from loc[] ? #7528

Answered by TomNicholas
johann-petrak asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @johann-petrak - sorry that there's nothing in the docstring for DataArray.loc, it should at the very least link to our general page on Indexing, which covers .loc as well as other indexing methods.

The table here states the difference between [] and .loc[] - the former indexes by position and the latter by label.

Your example DataArray has the integers 1, 2, 3 in the labels for the rows coordinate:

In [5]: a1
Out[5]: 
<xarray.DataArray (rows: 10, cols: 4)>
array([[ 0.63574108, -0.66717472,  0.00915737,  2.87035267],
       [ 0.14699325,  0.0393495 , -0.3325451 ,  1.72347164],
       [-1.08075426, -0.25283328, -0.22643869, -0.29025223],
       [ 0.64201311,  2.01351354,  0.64635188, -1…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@johann-petrak
Comment options

@dcherian
Comment options

@johann-petrak
Comment options

@johann-petrak
Comment options

Answer selected by johann-petrak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants