这是我的密码
listOTHERS_hpos = ['BLACKBERRY 7', 'SYMBIAN', 'NOKIA OS', 'BLACKBERRY 10', 'WINDOWS']
lastvalue_month = lastvalue_month.withColumn('handset_type',
when(col('handset_os').isin(listOTHERS_hpos) , lit('OTHERS')))
lastvalue_month.groupBy('handset_os').count().orderBy('count').show()
这是输出
+-------------+-----+
| handset_os|count|
+-------------+-----+
| WINDOWS| 6|
|BLACKBERRY 10| 8|
| NOKIA OS| 15|
| SYMBIAN| 39|
| BLACKBERRY 7| 43|
| UNDEFINED| 1218|
| APPLE IOS| 1496|
| OTHER| 3705|
| ANDROID|13218|
+-------------+-----+
按照代码应该是这样的
+-------------+-----+
| handset_os|count|
+-------------+-----+
| OTHERS| 111|
| UNDEFINED| 1218|
| APPLE IOS| 1496|
| OTHER| 3705|
| ANDROID|13218|
+-------------+-----+
应使用正确的列对列进行分组。此外,在
when
中使用.otherwise()
是有帮助的:相关问题 更多 >
编程相关推荐