For pandas series, you should not change s.sort_index (inplace = True) s?

Given this code:

s = pd.Series([1,2,3], index=['C','B','A'])
s.sort_index(inplace=True)

You shouldn't slook like this now :

A    3
B    2
C    1
dtype: int64

When I run this, it sremains unchanged. Perhaps I am confused by what the argument should do inplace. I thought he should have changed the series on which the method is being called.

For the record, this returns a sorted series, but it does this if you set it inplaceto True.

+4
source share
2 answers

. 0,17/ 0,17, ( ). 0.17.1.

. https://github.com/pydata/pandas/pull/11422

, inplace:

In [4]: s = s.sort_index()

In [5]: s
Out[5]:
A    3
B    2
C    1
dtype: int64
+9

:

s = pd.DataFrame([1,2,3], index=['C','B','A'])

s.sort_index(inplace=True)

s
Out[25]: 
   0
A  3
B  2
C  1

inplace sort_index DataFrame, . .

+2

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


All Articles