Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var some_df = Seq(
- ("A", "no"),
- ("B", "yes"),
- ("B", "yes"),
- ("B", "no")
- ).toDF(
- "user_id", "phone_number")
- +-------+------------+
- |user_id|phone_number|
- +-------+------------+
- | A| no|
- | B| yes|
- | B| yes|
- | B| no|
- +-------+------------+
- val omg_window = Window.partitionBy($"user_id")
- some_df = some_df.withColumn("my_col",
- count($"phone_number"==="yes").over(omg_window)).drop("phone_number")
- some_df.show()
- +-------+------+
- |user_id|my_col|
- +-------+------+
- | B| 3|
- | B| 3|
- | B| 3|
- | A| 1|
- +-------+------+
- User Id . my_col
- B . 2
- A . 0
Add Comment
Please, Sign In to add comment