The vague behavior of the Pandas.loc indexer

Consider the following DataFrame:

df = DataFrame({'A': [1, 2, 3]})

which corresponds to:

   A
0  1
1  2
2  3

If I replace the values ​​of two rows with .locindexer as follows:

data.loc[[1, 0], 'A'] = [101, 100]

then I expect (ordering the values ​​reflects the order of the indices):

     A
0  101
1    2
2  103

However, if I replace the values ​​of all rows as follows:

data.loc[[2, 0, 1], 'A'] = [1003, 1001, 1002]

then I unexpectedly (ordering the values ​​does not reflect the order of the indices):

      A
0  1003
1  1001
2  1002

Is this a function .locor an error? I am using Pandas 0.13.0.

Thank.

+4
source share

Source: https://habr.com/ru/post/1534250/


All Articles