Python 排序';熊猫.core.series.series';所以最大的值在中心
我有一个熊猫系列,看起来像这样:Python 排序';熊猫.core.series.series';所以最大的值在中心,python,pandas,Python,Pandas,我有一个熊猫系列,看起来像这样: import pandas as pd x = pd.Series([3, 1, 1]) print(x) 0 3 1 1 2 1 我想对输出进行排序,使最大值位于中间。像这样: 0 1 1 3 2 1 对于不同长度的序列(所有序列都按递减值排序),您是否也有这样做的想法。系列的长度总是奇数 多谢各位 Anna首先对值进行排序,然后通过以下方式使用连接值索引: x=pd.Series(范围(6))的预期输出是什么?
import pandas as pd
x = pd.Series([3, 1, 1])
print(x)
0 3
1 1
2 1
我想对输出进行排序,使最大值位于中间。像这样:
0 1
1 3
2 1
对于不同长度的序列(所有序列都按递减值排序),您是否也有这样做的想法。系列的长度总是奇数
多谢各位
Anna首先对值进行排序,然后通过以下方式使用连接值索引:
x=pd.Series(范围(6))
的预期输出是什么?预期输出为:0 2 4 6 5 3 1,但预期数字会相互镜像。我有两倍的数字2,两倍的数字3,依此类推。在上面的例子中是3,1,1。(预期输出:1,3,1)t也可以是6,4,4,2,2,1,1(预期输出:1,2,4,6,4,2,1)长度将始终为奇数。不需要排序,因为它们已排序。
x = pd.Series([6, 4, 4, 2, 2, 1, 1])
x = x.sort_values()
print (pd.concat([x[::2], x[len(x)-2:0:-2]]))
5 1
3 2
1 4
0 6
2 4
4 2
6 1
dtype: int64
x = pd.Series(range(7))
x = x.sort_values()
print (pd.concat([x[::2], x[len(x)-2:0:-2]]))
0 0
2 2
4 4
6 6
5 5
3 3
1 1
dtype: int64