1
PySpark DataFrameの小グループ内でどのように操作を行うことができるかを理解しようとしています。私は、次のスキーマを使用したDFを持っていると仮定します。PySpark:DataFrameの小グループ内で反復する
root
|-- first_id: string (nullable = true)
|-- second_id_struct: struct (nullable = true)
| |-- s_id: string (nullable = true)
| |-- s_id_2: int (nullable = true)
|-- depth_from: float (nullable = true)
|-- depth_to: float (nullable = true)
|-- total_depth: float (nullable = true)
データは次のようなものになりますので:私はしたいと思います
:各グループ内first_id
- グループのデータを、 s_id_2で昇順に並べ替えます。
- 余分な列
layer
は、このの順序を示す構造体またはルートのDataFrameに追加しますグループ内の。例えば
:
first_id | second_id | second_id_order
---------| --------- | ---------------
A1 | [B, 10] | 1
---------| --------- | ---------------
A1 | [B, 14] | 2
---------| --------- | ---------------
A1 | [B, 22] | 3
---------| --------- | ---------------
A5 | [A, 1] | 1
---------| --------- | ---------------
A5 | [A, 7] | 2
---------| --------- | ---------------
A7 | null | 1
---------| --------- | ---------------
一旦各first_id
は高々4 second_id_struct
を有するであろうグループ化。このような問題にどのようにアプローチすればよいでしょうか?
私は特に、グループ内の列の順序が重要なDataFramesの小グループ(1〜40行)内で反復操作を行う方法に興味があります。
ありがとうございます!