我是 AWS Glue 和 Pyspark 的新手,所以我在轉換作業時遇到了一些問題。我有兩個 DynamicFrames,其中一個包含其中一個列中的值,需要在另一個 DF 中作為單獨的列添加,列中的值需要是與另一列中的值對應的值第一個表中的id。這是它的外觀:
Table 1 Table2
-- ----- ----- -- ----- -----
|id|name |value| |id|col1 |col2 |
-- ----- ----- -- ----- -----
| 1|name1| 10 | | 1|str1 |val1 |
-- ----- ----- -- ----- -----
| 2|name2| 20 | | 2|str2 |val2 |
-- ----- ----- -- ----- -----
我需要新格式為:
Table2
-- ----- ----- ----- -----
|id|col1 |col2 |name1|name2|
-- ----- ----- ----- -----
| 1|str1 |val1 | 10 | | <--- add 10 only here because the id from the row in the first table must match the id from the second table
-- ----- ----- ----- -----
| 2|str2 |val2 | | 20 | <--- add 20 only here because the id from the row in the first table must match the id from the second table
-- ----- ----- ----- -----
uj5u.com熱心網友回復:
您必須加入 id 列。
df = Join.apply(table1, table2, 'id', 'id')
你可以在這里閱讀:
https://docs.aws.amazon.com/glue/latest/dg/aws-glue-api-crawler-pyspark-transforms-join.html https://dk81.github.io/dkmathstats_site/set-theory-sql .html
uj5u.com熱心網友回復:
假設 2 個資料幀被命名為df1和df2。
df3 = df1.groupBy('id').pivot('name').sum('value')
df4 = df2.join(df3, on='id', how='inner')
df4.show(truncate=False)
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/329053.html
下一篇:詩運行worker.py|FileNotFound[Errno2]沒有那個檔案或目錄:b'/snap/bin/worker.py'
