apache-spark - 如何将我的输出作为每次运行的新行插入
问题描述
我有一个类似于下面的数据集
df =
+-------------+---------------+-----------+
date delivery Value
+-------------+---------------+-----------+
01/01/2018 yes 0
02/01/2018 no 3
03/01/2018 yes 3
04/01/2018 no 0
01/02/2018 yes 3
02/02/2018 yes 0
03/02/2018 yes 0
04/02/2018 yes 2
01/03/2018 no 0
02/03/2018 yes 0
03/03/2018 no 3
04/03/2018 no 2
我试图始终在每次运行时插入我的代码输出,并将当前标记作为新行。目前我试过:
total = df.count()
df2 = df.filter(df.Value==0).groupBy("delivery")\
.count()\
.withColumn("percent",(F.col('cnt_grp')/total)*100) \
.withColumn("date",current_timestamp())
但每次我运行这个我只得到两行。而不是每次运行的两个新行。我想要的输出应该类似于这个
+-------------+---------------+----------------------+----------------------+
date delivery valuewithzero percentage
+-------------+---------------+----------------------+----------------------+
19/2021 yes 4 33.3%
19/2021 no 2 16.6%
20/2021 yes 4 33.3%
20/2021 no 2 16.6%
21/2021 yes 4 33.3%
21/2021 no 2 16.6%
解决方案
推荐阅读
- lua - Kong v1.0.2 的自定义插件已启用但未安装
- python - 如何摆脱python中的嵌套循环
- c# - 使用双泛型的 C# 类:当它们都应该相同时只给出一个?
- python - Python:针对不同特定工作人员的分布式任务队列
- r - 与 R 的字符串比较
- python - scrollintoview 没有滚动到元素(python)
- r - 如何在 R 中通过一个脚本多次预测一个变量?
- reactjs - 错误:操作必须是普通对象。使用自定义中间件进行非 api 调用更新的异步操作
- ios - AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo 在 ipad 上返回 nil
- php - 从特定 url 重定向登录表单