为什么在Pandas Series上调用.sort()函数对它的值进行原位排序而不返回任何内容? [英] Why calling .sort() function on Pandas Series sorts its values in-place and returns nothing?
问题描述
对不起,我认为我在这里缺少一些非常基本的内容:
Sorry I think I am missing something very basic here:
>>> Series([3,4,0,3]).sort()
无输出,而
>>> Series([3,4,0,3]).order()
2 0
0 3
3 3
1 4
dtype: int64
sort()我缺少什么?
what am I missing with sort()?
谢谢
感谢您的回答,我现在意识到这已经就位了.但是我不明白为什么
Thanks for the answers, I do realize now that this is sorting in place. But I don't understand why
>>> s = Series([3,4,0,3]).sort()
>>> s
不返回已排序的系列.如果我了解手册,它应该返回系列排序到位.
does not return the sorted Series. If I understand the manual it should return the series sorted in place.
推荐答案
.sort()
对就地进行排序.
这意味着在调用.sort()
之后,已对现有数组进行了排序.它不会返回任何内容.
That means that after you call .sort()
, your existing array has been sorted. It doesn't return anything.
以核心" Python为例:
To take an example from "core" Python:
In [175]: L = [2, 3, 1, 5]
In [176]: L.sort()
In [177]: print(L)
[1, 2, 3, 5]
按值对值和索引标签进行排序.与ndarray API兼容.没有返回值
Sort values and index labels by value, in place. For compatibility with ndarray API. No return value 另请参见: Series.sort()和Series.order()有什么区别? See also: What's the difference between Series.sort() and Series.order()? 这篇关于为什么在Pandas Series上调用.sort()函数对它的值进行原位排序而不返回任何内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!