作为一个新的Spark,我正在工作的东西和面临的困难。任何线索都会有帮助。我正试图从Dataframe创建一个json,但tojson函数并没有帮到我。所以我的输出数据框如下:
+---------+------------------+-------------------------+
|booking_id| status |count(status)|
+---------+------------------+-------------------------+
| 132 | rent count. | 6|
| 132 | rent booked | 24|
| 132 | rent delayed | 6|
| 134 | rent booked | 34|
| 134 | rent delayed. | 21|
我要寻找的输出是一个Dataframe,它将包含预订id和状态,并将其计数为json
+---------+-------------------------------------------+
|booking_id| status_json
+---------+-------------------------------------------+
| 132 | { "rent count": 6, "rent booked": 24, "rent delayed": 6}
| 134 | { "rent booked": 34, "rent delayed": 21}
提前谢谢。
2条答案
按热度按时间pwuypxnk1#
oo7oh9g92#
为了
Spark2.4
,使用map_from_arrays
.