wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

PySpark Quiz Round

Total questions: 11

Worksheet time: 6mins

Name
Class
Date
1.

Which of the following is a transformation operation in PySpark?

a)

count()

b)

filter()

c)

reduce()

d)

collect()

2.

Which of the following is true for RDD?

a)

RDD is programming paradigm

b)

RDD in Apache Spark is an immutable collection of objects

c)

It is a database

d)

None of the above

3.

words_list = sc.parallelize ( ["pyspark", "quiz", "questions", "at", "quiz.com"] )

filtered_words = words_list.filter(lambda x: 'quiz' in x)

matched_words= filtered_words.collect()

print(matched_words)

a)

[ "quiz", "quiz.com" ]

b)

[ "quiz" ]

c)

["quiz.com" ]

d)

Error

4.

Let us consider, we have a data frame "df". Then what does the expression '[.]{2,}' signify for the following transformation?

df = df.withColumn('var_addrss', sf.regexp_replace('var_addrss', '[.]{2,}', ''))

a)

A single dot (".") followed by 2 integers

b)

A single dot (".") followed by the integer '2'

c)

Single dot (".") appearing twice consecutively

d)

None of these

5.

Let us consider, we have a data frame "df". Then what does the expression '^[0]*' signify for the following transformation?

df = df.withColumn('var_addrss', sf.regexp_replace('var_addrss', '^[0]*', ''))

a)

The value starts with 0 OR followed by a sequence of 0s

b)

The value starts with 0 and ends with 0

c)

The value starts with 0 and followed by a sequence of 0s

d)

The value starts with anything other than 0

6.

Let's assume we have the following data frame "df".

How to display the 'age' column in descending order?

a)

display(df.orderBy(df.age.desc()))

b)

display(df.sort(df.age.desc()))

c)

display(df.orderBy(df.age, sort = desc()))

d)

None of these

7.

What will the data type of the columns for the following PySpark data frame "df"?

df = spark.read.format("csv").option("header", "true").option("inferSchema", "false").option("delimeter", ",").load("/mnt/temp/test.csv")

a)

Data types of columns will be int

b)

Data types of columns will be read as per the data types defined in the file

c)

Data types of all columns will be string

d)

None of the above

8.

Let's consider, we have this data frame "df".

How to find the sum of column "aggregation" w.r.t each partition?

a)

df = df.withColumn('sum_total', sum('aggregation').over(Window.partitionBy('partition'))

display(df)

b)

df.groupBy("partition").sum("aggregation").show()

c)

display(df.withColumn('sum_total', sum('aggregation').over(Window.partitionBy('partition')))

d)

None of the above

9.

What is the function to convert column data type from Unix Time Seconds to Date and Timestamp?

a)

None of these

b)

Both the commands are correct

c)

unix_timestamp()

d)

from_unixtime()

10.

Consider, we have this data frame "df" (as shown in the pic).

How to replace the 1st 3 values of column 'alchohol' as "Nan"?

a)

import pandas as pd

import numpy as np

df.iloc[0:3, 0] = np.nan

df

b)

import pandas as pd

import numpy as np

df.loc[0:3, 0] = np.nan

df

c)

import pandas as pd

import numpy as np

df.iloc[0:3] = np.nan

df

d)

import pandas as pd

import numpy as np

df.iloc[0:3] = np.nan

df.show()

11.

Which of the following options will remove duplicates from the array column "address_struct_str"?

1) from pyspark.sql.functions import array_distinct

df = df.withColumn("address_dict", array_distinct("address_struct_str"))

2) from pyspark.sql.functions import udf

dist_addr = udf(lambda row: list(set(row)), ArrayType(StringType()))

df = df.withColumn("address_dict", dist_addr("address_struct_str"))

a)

Option-1 is correct

b)

Option-2 is correct

c)

Both options- 1 & 2 are correct

d)

None of these are correct