When you pass a string to the filter function, the string is interpreted as SQL. Count is a SQL keyword and using count as a variable confuses the parser. This is a small bug. You can easily avoid this. Instead of using a String use a column expression, as shown below:
df.groupBy("x").count()
.filter($"count" >= 2)// or .filter("`count` >= 2")
.show()
If you want to know more about Spark, then do check out this awesome video tutorial: