我在變數中有以下字典:
sk_channel_types = {"facebooknotification": 2,
"facebookmessenger": 9,
"onsitenotification": 3,
"pushnotification": 6,
"pushnotificationmessage": 6,
"lightbox": 4,
"onsitemessage": 7,
"mailmessage": 1}
sk_story_types = {"welcome": 7,
"rescue": 13,
"frequency": 4,
"abandoncart": 6,
"pricedrop": 16,
"manual": 5,
"searchbykeyword": 30,
"sazonality": 31,
"bestdayforpurchase": 28,
"pricechange": 32,
"availability": 33,
"toptrending": 1,
"toptrendingbycluster": 2,
"toptrendingwithpricelimit": 3,
"frequencyview": 4,
"manualnotification": 5,
"trending": 9,
"toptrendingbykeyword": 9}
這是我目前的火花資料框:
| ID | 故事型別 | 型別 | 故事 ID |
|---|---|---|---|
| abcdefghijklmnopqrst | 棄車 | 郵件訊息 | 56465465456456456465 |
| l?dk?lskd?lsdk?lskd? | 手動通知 | 郵件訊息 | 60983099380938390833 |
| 哇哇哇哇哇哇哇 | 手動通知 | 郵件訊息 | 49438093890484984949 |
| skl?sk?lskdkcnopeieo | 手動通知 | 郵件訊息 | 93084098409840984098 |
| 2d5fe941380938098948 | 手動通知 | 郵件訊息 | 49809380398094894844 |
| 9883jkjd3eu0dj0j3930 | 手動通知 | 郵件訊息 | 636f50c9380938093893 |
我需要根據變數用各自的數字替換 StoryType 和 Type 列,如下所示:
| ID | 故事型別 | 型別 | 故事 ID |
|---|---|---|---|
| abcdefghijklmnopqrst | 6 | 1 | 56465465456456456465 |
| l?dk?lskd?lsdk?lskd? | 5 | 1 | 60983099380938390833 |
| 哇哇哇哇哇哇哇 | 5 | 1 | 49438093890484984949 |
| skl?sk?lskdkcnopeieo | 5 | 1 | 93084098409840984098 |
| 2d5fe941380938098948 | 5 | 1 | 49809380398094894844 |
| 9883jkjd3eu0dj0j3930 | 5 | 1 | 636f50c9380938093893 |
我怎樣才能做到這一點?我可以使用低的情況嗎?我是 Pyspark 的新手。
uj5u.com熱心網友回復:
由于字典很小,因此有效的方法是使它們成為廣播資料集并將它們加入資料集。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/432899.html
