Which of the following code blocks returns all unique values of column storeId in DataFrame transactionsDf?
transactionsDf.select('storeId').dropDuplicates().count()
Correct! After dropping all duplicates from column storeId, the remaining rows get counted, representing the number of unique values in the column.
transactionsDf.select(count('storeId')).dropDuplicates()
No. transactionsDf.select(count('storeId')) just returns a single-row DataFrame showing the number of non-null rows. dropDuplicates() does not have any effect in this context.
transactionsDf.dropDuplicates().agg(count('storeId'))
Incorrect. While transactionsDf.dropDuplicates() removes duplicate rows from transactionsDf, it does not do so taking only column storeId into consideration, but eliminates full row duplicates
instead.
transactionsDf.distinct().select('storeId').count()
Wrong. transactionsDf.distinct() identifies unique rows across all columns, but not only unique rows with respect to column storeId. This may leave duplicate values in the column, making the count
not represent the number of unique values in that column.
transactionsDf.select(distinct('storeId')).count()
False. There is no distinct method in pyspark.sql.functions.
Argelia
2 months agoMarleen
20 days agoAmber
20 days agoMyong
22 days agoElin
2 months agoBeckie
2 months agoGracia
2 months agoEstrella
2 months agoReuben
2 months agoMalinda
2 months agoMicaela
1 months agoLisbeth
1 months agoCletus
2 months agoCatalina
2 months agoLorrine
3 months agoNada
3 months agoJenelle
2 months agoLemuel
2 months agoCorinne
2 months agoYoko
2 months agoLauran
3 months agoDoyle
3 months agoLeontine
3 months ago