26.13.1 PgqlResultSetからPgxFrameへの変換
次の例では、
PgqlResultSet
をPgxFrame
に保存する方法について説明します。
opg4j> var pg = session.readGraphByName("BANK_GRAPH",GraphSource.PG_PGQL)
opg4j> var rs = pg.queryPgql("SELECT e.* FROM MATCH (v1:Accounts)-[e:Transfers]->(v2:Accounts) LIMIT 5")
opg4j> var rsFrame = rs.toFrame()
opg4j> rsFrame.print()
+--------------------------------------------------+
| FROM_ACCT_ID | TO_ACCT_ID | AMOUNT | DESCRIPTION |
+--------------------------------------------------+
| 999 | 934 | 1000.0 | transfer |
| 999 | 71 | 1000.0 | transfer |
| 999 | 839 | 1000.0 | transfer |
| 999 | 891 | 1000.0 | transfer |
| 999 | 919 | 1000.0 | transfer |
+--------------------------------------------------+
$4 ==> oracle.pgx.api.frames.internal.PgxFrameImpl@39a1c200
import oracle.pgx.api.frames.*;
PgxGraph pg = session.readGraphByName("BANK_GRAPH",GraphSource.PG_PGQL);
PgqlResultSet rs = pg.queryPgql("SELECT e.* FROM MATCH (v1:Accounts)-[e:Transfers]->(v2:Accounts) LIMIT 5");
PgxFrame rsFrame = rs.toFrame();
rsFrame.print();
>>> pg = session.read_graph_by_name('BANK_GRAPH','pg_pgql')
>>> rs = pg.query_pgql("SELECT e.* FROM MATCH (v1:Accounts)-[e:Transfers]->(v2:Accounts) LIMIT 5")
>>> rs_frame = rs.to_frame()
>>> rs_frame.print()
+--------------------------------------------------+
| FROM_ACCT_ID | TO_ACCT_ID | AMOUNT | DESCRIPTION |
+--------------------------------------------------+
| 1 | 418 | 1000.0 | transfer |
| 1 | 584 | 1000.0 | transfer |
| 1 | 644 | 1000.0 | transfer |
| 1 | 672 | 1000.0 | transfer |
| 1 | 259 | 1000.0 | transfer |
+--------------------------------------------------+
PgqlResultSetからpandas DataFrameへの変換
次の例に示すように、PgqlResultSet
をpandas DataFrame
に保存することもできます。
>>> rs.to_pandas()
FROM_ACCT_ID TO_ACCT_ID AMOUNT DESCRIPTION
0 999 934 1000.0 transfer
1 999 71 1000.0 transfer
2 999 839 1000.0 transfer
3 999 891 1000.0 transfer
4 999 919 1000.0 transfer
親トピック: PgxFrameの表形式データ構造