Which of the following code blocks returns the number of unique values in column storeId of 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.
Danica
5 months agoMelissa
5 months agoJanet
5 months agoAntonio
4 months agoMelita
4 months agoSharmaine
5 months agoYan
4 months agoStephaine
4 months agoStephaine
4 months agoStephaine
5 months agoTheodora
5 months agoRichelle
5 months agoTy
5 months agoEulah
5 months agoShawnda
6 months agoLinwood
5 months agoTresa
5 months agoVeronika
5 months agoJodi
5 months agoAnastacia
5 months agoSylvia
5 months ago