def count_values(expr, sort=True):
 result = by(expr, count=expr.count())
 if sort:
  result = result.sort('count', ascending=False)
 return result

def count_values ( expr , sort = True ) : result = by ( expr , count = expr . count ( ) ) if sort : result = result . sort ( 'count' , ascending = False ) return result
count occurrences of elements in this column sort by counts by default add sort=false keyword to avoid this behavior .