第一次使用Spark SQL。我有一个带有以下列的DF:“ tweet_date”,“ user_screen_name”,“ user_id_str”。我的目标是选择在5个不同日期(tweet_date)发布的所有user_id_str和user_screen_names。
我的代码当前看起来像这样,但我认为这是错误的。
task12=spark.sql("SELECT DISTINCT user_id_str, user_screen_name FROM tweet2 WHERE (user_id_str)>=5")
更换时
WHERE (user_id_str)>=5
#to
WHERE (tweet_date)>=5
我的输出df为空白
非常感谢您的帮助
您可以在user_screen_names..etc列上group by
和count(distinct(tweet_date))
上获取tweet_dates的计数。
having
子句过滤结果。Sample Query:
#this query results names where tweet_date count is atleast 5
spark.sql("select user_screen_name,count(distinct(tweet_date)) cnt from dd group by user_screen_name having cnt >= 5").show()