Pyspark's Dataframe study (1)

Source: Internet
Author: User
Tags pyspark
From pyspark.sql import sparksession
spark= sparksession\
                . Builder \.
                appName ("DataFrame") \
                . Getorcreate ()
#1生成JSON数据
Stringjsonrdd = spark.sparkContext.parallelize ((' ' ' {'
    id ': ' 123 ',
    ' name ' : "Katie",
    "age": +,
    "Eyecolor": "Brown"} "", ""
{"
    id": "234",
    "name": "Michael",
    "Age": "
    eyecolor": "Green"} "", ""
{"
    ID": "345",
    "name": "Simone",
    "age" :
    "Eyecolor": "Blue"} ")
#2创建DataFrame
Swimmersjson = Spark.read.json (Stringjsonrdd)
#3创建一个临时表
Swimmersjson.createorreplaceglobaltempview ("Swimmersjson")
#4查看前几行
Print Swimmersjson.show () #默认是10行
 
 
#5可以通过编写sql语句查询
Print Spark.sql ("SELECT * from Swimmersjson"). Collect ()
#6打印模式
Print Swimmersjson.printschema ()

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.