Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.

Unlimited Access

Get Unlimited Contributor Access to the all ExamTopics Exams!
Take advantage of PDF Files for 1000+ Exams along with community discussions and pass IT Certification Exams Easily.

Exam Certified Associate Developer for Apache Spark topic 1 question 44 discussion

The code block shown below should create a single-column DataFrame from Python list years which is made up of integers. Choose the response that correctly fills in the numbered blanks within the code block to complete this task.
Code block:
_1_._2_(_3_, _4_)

  • A. 1. spark
    2. createDataFrame
    3. years
    4. IntegerType
  • B. 1. DataFrame
    2. create
    3. [years]
    4. IntegerType
  • C. 1. spark
    2. createDataFrame
    3. [years]
    4. IntegertType
  • D. 1. spark
    2. createDataFrame
    3. [years]
    4. IntegertType()
  • E. 1. spark
    2. createDataFrame
    3. years
    4. IntegertType()
Show Suggested Answer Hide Answer
Suggested Answer: D 🗳️

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
peekaboo15
Highly Voted 1 year, 4 months ago
The answer should be E because Year is already a python list.
upvoted 9 times
...
zic00
Most Recent 1 week, 5 days ago
Selected Answer: E
it uses spark.createDataFrame correctly with the Python list years and the appropriate data type IntegerType(). All other options have errors either in syntax or the use of PySpark methods and types.
upvoted 1 times
...
jds0
1 month, 2 weeks ago
Selected Answer: E
E is the right answer See code below: # Create a DataFrame from a list of integers from pyspark.sql import SparkSession from pyspark.sql.types import IntegerType spark = SparkSession.builder.appName("MyApp").getOrCreate() years = [2017, 2018, 2019] df = spark.createDataFrame(years, IntegerType()) df.show() df.printSchema()
upvoted 2 times
...
znets
6 months, 2 weeks ago
Selected Answer: E
E is the most suitable, but it also contains an error. In PySpark, the correct class name for the integer data type is IntegerType (not "IntegertType").
upvoted 1 times
...
mahmoud_salah30
8 months, 1 week ago
e is the right
upvoted 1 times
...
juliom6
10 months, 1 week ago
Selected Answer: E
E is correct: from pyspark.sql.types import IntegerType years = [2023, 2024] print(type(years)) storesDF = spark.createDataFrame(years, IntegerType()) storesDF.show() <class 'list'> +-----+ |value| +-----+ | 2023| | 2024| +-----+
upvoted 1 times
...
juadaves
10 months, 3 weeks ago
D from pyspark.sql.types import IntegerType spark.createDataFrame([1991,2023],IntegerType()).show() +-----+ |value| +-----+ | 1991| | 2023| +-----+
upvoted 1 times
carlosmps
2 months, 2 weeks ago
it's E. years is already a list
upvoted 2 times
...
...
thanab
11 months, 3 weeks ago
Selected Answer: E
1. spark 2. createDataFrame 3. years 4. IntegertType()
upvoted 1 times
...
cookiemonster42
1 year, 1 month ago
Selected Answer: E
if years is variable, it works, just tested it: years = [1, 3, 4, 5 , 9] df7 = spark.createDataFrame(years, IntegerType()) df7.show() this works as well: df7 = spark.createDataFrame([1, 3, 4, 5 , 9], IntegerType()) df7.show() this won't work: df7 = spark.createDataFrame([years], IntegerType()) df7.show() so, the answer is E
upvoted 1 times
...
singh100
1 year, 1 month ago
E. D is giving an error .
upvoted 1 times
...
zozoshanky
1 year, 1 month ago
D throws a big error. /usr/local/spark/python/pyspark/sql/types.py in verify_acceptable_types(obj) 1291 # subclass of them can not be fromInternal in JVM 1292 if type(obj) not in _acceptable_types[_type]: -> 1293 raise TypeError(new_msg("%s can not accept object %r in type %s" 1294 % (dataType, obj, type(obj)))) 1295 TypeError: field value: IntegerType can not accept object [1, 2, 3, 4, 5] in type <class 'list'> E is correct answer from pyspark.sql.types import IntegerType a = [1,2,3,4,5] spark.createDataFrame(a, IntegerType()).show()
upvoted 1 times
...
Indiee
1 year, 4 months ago
Two responses 1. D is an error. E will split the array into rows 2. spark.createDataFrame([arraryVar_name],ArrayType(IntegerType())) will store the whole array as a row
upvoted 2 times
...
Indiee
1 year, 4 months ago
Agreed
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...