我有一个的大数据帧有222列我想要做像下面的例子认沽值从一行到另一阶dataaframe
|id |day |col1 |col2 | col3 ....................
+----------+----------------+-------+-----+
| 329| 0| null|2.0
| 329| 42| null|null
| 329| 72| 5.55|null
| 329| 106| null|null
| 329| 135| null|3.0
| 329| 168| null|4.0
| 329| 189| 4.995|null
| 329| 212| null|6.0
| 329| 247| null|null
| 329| 274| null|8.0
|id | day |col1 |col2 |.......................
+----------+----------------+-------+-----+
| 329| 0| null|2.0
| 329| 42| null|2.0
| 329| 72| 5.55|2.0
| 329| 106| 5.55|2.0
| 329| 135| 5.55|3.0
| 329| 168| 5.55|4.0
| 329| 189| 4.995|4.0
| 329| 212| 4.995|6.0
| 329| 247| 4.995|6.0
| 329| 274| 4.995|8.0
.
.
.
.
.
1.read行1 2.我有85K的唯一ID的和每个ID有10个结果(只有一个ID的示出的示例)3.如果 在第2行的数据不存在,则把它从ID的前一行
我得到导致这样
id | day |original_col1 |Result_col1|prevValue|
+----------+----------------+--------------+-----------+---------+
| 329| 0| null | null | null|
| 329| 42| null | null | null|
| 329| 72| 5.55 | 5.55 | null|
| 329| 106| null | 5.55 | 5.55|
| 329| 135| null | null | null|
| 329| 168| null | null | null|
| 329| 189| 4.995 | 4.995 | null|
| 329| 212| null | 4.995 | 4.995|
| 330|....................................................
| 330|.....................................................
.
是否有确定性的方式来排序数据,以便能够使用窗口函数(滞后)?我知道你希望在由col“id”定义的分区中应用上面的逻辑,但是除非你有办法定义一些排序(假定顺序很重要),对于id为“1”的分区,对于“col1”你可能会在第1/2/3行得到空值,结果会有所不同。如果数据没有排序,您可以尝试使用monotonically_increasing_id()函数在从文件/源读取数据后立即生成order_id。 – Traian
我忘了添加一列请现在检查,ID是唯一的,强制性ID不过是用户而且每个ID都少于6条记录。 –