Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在Spark sortBy中同时对两个值进行排序_Python_Apache Spark - Fatal编程技术网

Python 在Spark sortBy中同时对两个值进行排序

Python 在Spark sortBy中同时对两个值进行排序,python,apache-spark,Python,Apache Spark,我想对数据的第一个和第三个值进行排序,第一个值按升序排列,第三个值按降序排列。我知道我应该使用numPartitions,但我不知道怎么写。 我试过: 但结果表明,x[1][0]仍然是按升序排序的。 如何更改代码? 输出 +---+---+ | c1| c2| +---+---+ | 10| a1| | 11| a2| | 13| a3| | 13| a3| +---+---+ +---+---+ | c1| c2| +---+---+ | 10| a1| | 11| a2| | 13| a3

我想对数据的第一个和第三个值进行排序,第一个值按升序排列,第三个值按降序排列。我知道我应该使用numPartitions,但我不知道怎么写。 我试过:

但结果表明,x[1][0]仍然是按升序排序的。 如何更改代码?

输出

+---+---+
| c1| c2|
+---+---+
| 10| a1|
| 11| a2|
| 13| a3|
| 13| a3|
+---+---+

+---+---+
| c1| c2|
+---+---+
| 10| a1|
| 11| a2|
| 13| a3|
| 13| a3|
+---+---+

+---+---+
| c1| c2|
+---+---+
| 13| a3|
| 13| a3|
| 11| a2|
| 10| a1|
+---+---+

输出

+---+---+
| c1| c2|
+---+---+
| 10| a1|
| 11| a2|
| 13| a3|
| 13| a3|
+---+---+

+---+---+
| c1| c2|
+---+---+
| 10| a1|
| 11| a2|
| 13| a3|
| 13| a3|
+---+---+

+---+---+
| c1| c2|
+---+---+
| 13| a3|
| 13| a3|
| 11| a2|
| 10| a1|
+---+---+

我发现
.sortBy(lambda x:(x[0][0],-x[1][0]),numPartitions=1
应该可以工作,但是你的也可以。我发现
.sortBy(lambda x:(x[0][0],-x[1][0]),numPartitions=1
应该可以工作,但是你的也可以。
+---+---+
| c1| c2|
+---+---+
| 10| a1|
| 11| a2|
| 13| a3|
| 13| a3|
+---+---+

+---+---+
| c1| c2|
+---+---+
| 10| a1|
| 11| a2|
| 13| a3|
| 13| a3|
+---+---+

+---+---+
| c1| c2|
+---+---+
| 13| a3|
| 13| a3|
| 11| a2|
| 10| a1|
+---+---+