[Spark] [Python]sortbykey Example

Source: Internet
Author: User
Tags hdfs dfs pyspark

[Spark] [Python]sortbykey Example:

[Email protected] ~]$ HDFs dfs-cat test02.txt
00002 sku010
00001 sku933
00001 sku022
00003 sku888
00004 sku411
00001 sku912
00001 sku331
[Email protected] ~]$


Mydata001=sc.textfile ("Test02.txt")
Mydata002=mydata001.map (Lambda line:line.split ("))

Mydata002.take (3)
OUT[4]: [[u ' 00002 ', U ' sku010 '], [u ' 00001 ', U ' sku933 '], [u ' 00001 ', U ' sku022 ']

Mydata003=mydata002.sortbykey ()

In [9]: Mydata003.take (5)

OUT[9]:
[[u ' 00001 ', U ' sku933 '],
[u ' 00001 ', U ' sku022 '],
[u ' 00001 ', U ' sku912 '],
[u ' 00001 ', U ' sku331 '],
[u ' 00002 ', U ' sku010 ']

In [10]:


API Reference:
Https://spark.apache.org/docs/latest/api/python/pyspark.html#pyspark.RDD

[Spark] [Python]sortbykey Example

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.