14.12.10 PgxFrame Helpers
PgxFrame
supports the following operations:
head
tail
select
renameColumns
Head Operation
The head
operation can be used to only keep the first rows of a PgxFrame
. (The result is deterministic only for ordered PgxFrame
.)
opg4j> vecFrame.head(2).print();
vecFrame.head(2).print();
The output appears as follows:
+-----------------------------------------------------------+
| intProp | intProp2 | vectProp | stringProp | vectProp2 |
+-----------------------------------------------------------+
| 0 | 2 | 0.1;0.2;0.3 | testProp0 | 0.1;0.2 |
| 1 | 1 | 0.1;0.2;0.3 | testProp10 | 0.1;0.2 |
+-----------------------------------------------------------+
Tail Operation
The tail
operation can be used to only keep the last rows of a PgxFrame
. (The result is deterministic only for ordered PgxFrame
).
opg4j> vecFrame.tail(2).print()
vecFrame.tail(2).print()
The output appears as follows:
+-----------------------------------------------------------+
| intProp | intProp2 | vectProp | stringProp | vectProp2 |
+-----------------------------------------------------------+
| 2 | 3 | 0.1;0.2;0.3 | testProp30 | 0.1;0.2 |
| 3 | 1 | 0.1;0.2;0.3 | testProp40 | 0.1;0.2 |
+-----------------------------------------------------------+
Select Operation
The select
operation can be used to keep only a specified list of columns of an input PgxFrame
.
opg4j> var vecFrame_selected = vecFrame.select("vectProp2", "vectProp", "stringProp")
PgxFrame vecFrame_selected = vecFrame.select("vectProp2","vectProp","stringProp");
vec_frame_selected=vec_frame.select("vectProp2","vectProp","stringProp")
The result may appear as follows:
+--------------------------------------+
| vectProp2 | vectProp | stringProp |
+--------------------------------------+
| 0.1;0.2 | 0.1;0.2;0.3 | testProp0 |
| 0.1;0.2 | 0.1;0.2;0.3 | testProp10 |
| 0.1;0.2 | 0.1;0.2;0.3 | testProp20 |
| 0.1;0.2 | 0.1;0.2;0.3 | testProp30 |
| 0.1;0.2 | 0.1;0.2;0.3 | testProp40 |
+--------------------------------------+
Rename PgxFrame Columns
You can rename the columns in a PgxFrame
to customized names as follows:
opg4j> var vecFrame_renamed = vecFrame.renameColumns(
renaming("vectProp2", "vectProp2_renamed"),
renaming("vectProp", "vectProp_renamed"),
renaming("stringProp", "stringProp_renamed")
)
vecFrame_renamed = vecFrame.renameColumns(renaming("vectProp2", "vectProp2_renamed"),
renaming("vectProp", "vectProp_renamed"),
renaming("stringProp", "stringProp_renamed"));
The renamed PgxFrame
appears as follows:
+--------------------------------------------------------------------------------+
| intProp | intProp2 | vectProp_renamed | stringProp_renamed | vectProp2_renamed |
+--------------------------------------------------------------------------------+
| 0 | 2 | 0.1;0.2;0.3 | testProp0 | 0.1;0.2 |
| 1 | 1 | 0.1;0.2;0.3 | testProp10 | 0.1;0.2 |
| 1 | 2 | 0.1;0.2;0.3 | testProp20 | 0.1;0.2 |
| 2 | 3 | 0.1;0.2;0.3 | testProp30 | 0.1;0.2 |
| 3 | 1 | 0.1;0.2;0.3 | testProp40 | 0.1;0.2 |
+--------------------------------------------------------------------------------+
Parent topic: PgxFrames Tabular Data-Structure