我有一个数据帧df3: -
test_df3.show()
+----------------------+-------------------+
|count(user_name)|count(team_id)|
+----------------------+-------------------+
| 10 | 10|
+----------------------+-------------------+
我需要从两列以上创建一个json&添加到新列
udf = UserDefinedFunction(lambda x,y: {"user_count":x, "team_count":y}, StringType())
上面我正在使用StringType,因为json_type不可用,
test_df3 = test_df3.withColumn("new",udf(col("count(user_name)"), col("count(team_id)"))).select("new")