我得到了以下Spark数据帧,它由Variable进行分区。
+--------+--------------------+-------+---+
|Variable| Time| Value| id|
+--------+--------------------+-------+---+
| 7508|2015-08-20 12:01:...| 40.175| 16|
| 14491|2015-08-20 12:01:...|-51.787| 16|
| 8309|2015-08-20 12:01:...| 61.093| 16|
| 17051|2015-08-20 12:01:...| 30.362| 16|
| 18259|2015-08-20 12:01:...| 59.118| 16|
| 603|2015-08-20 12:01:...|249.847| 16|
| 10745|2015-08-20 12:01:...| 59.214| 16|
| 17107|2015-08-20 12:01:...| 36.235| 16|
| 18516|2015-08-20 12:01:...| 65.0| 16|
| 12750|2015-08-20 12:01:...| 99.392| 16|
+--------+--------------------+-------+---+
ID列表示"小"变量值为特定时间的观察值的事件集。现在我想根据事件ID对数据进行分组,以便我可以对这些观察结果进行一些统计,因为我们说事件ID = 16。 说明:我的目标是将事件的所有变量的所有观察结果作为用户定义方法的输入。
我目前的代码如下。 问题:有更有效的方法吗?
def combine(iter):
rows = list(iter)
if not rows:
return
df_pd = pd.DataFrame(rows)
... # do some Pandas analytics (on the Spark data node)
return df_pd
ref = ref.repartition("id").mapPartitions(combine).collect()