亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Python Pandas:將一列的值檢查到另一個數據框的列中

Python Pandas:將一列的值檢查到另一個數據框的列中

絕地無雙 2023-03-16 17:54:19
我有兩個數據框,如下所示:df:         Review Text                                        Noun                                             Thumbups   Rating    I've been using this app for over a month. It ...   [app, month, job, track, ATV, replay, animatio...         2.0   4    Would be nice to be able to import files from ...   [My, Tracks, app, phone, Google, Drive, import...         6.0   5    When screen off it shows a straight line. Not ...   [screen, line, route]                                     1.0   3    No Offline Maps! It used to have offline maps ...   [Offline, Maps, menu, option, video, exchange,...         20.0  1    Great application. Designed with very well tho...   [application, application]                                20.0  5    Great App. Nice and simple but accurate. Wish ...   [Great, App, Nice, Exported]                                0.0 5    Does just what it says. Had a couple of questi...   [couple, service]                                         0.0   5    Save For Offline - This does not work. The rou...   [Save, Offline, route, filesystem]                       12.0   1    Since latest update app will not run. Subscrip...   [update, app, Subscription, March, application]           9.0   5    Great app. Love it! And all the things it does...   [Great, app, Thank, work]                                1.0    5    I have paid for subscription but keeps telling...   [subscription, trial, period]                            0.0    2    Error: The route cannot be save for no locatio...   [Error, route, i, GPS]                                   0.0    2df1:Noun    Thumb_countaccuracy    1.0almost      1.0animation   2.0antarctica  1.0app         25.0application 29.0apps        1.0atv         2.0august      3.0battery     1.0我想檢查 df1 的“Noun”列的值是否出現在 df 的“Noun”列中,然后在 df1 中創建一個名為“average”的新列,并取 df 行的“Rating”列的平均值,其中 Noun現值。
查看完整描述

1 回答

?
人到中年有點甜

TA貢獻1895條經驗 獲得超7個贊

樣本輸出會非常有用。在沒有它的情況下,我的嘗試;


df.Noun=df.Noun.str.strip('[]')#Strip corner brackets

df.Noun=df.Noun.str.split(",")#Make list again.

df=df.explode('Noun')#Get each item in df.Noun 

df[df.Noun.str.contains(('|').join(df1.Noun.values.tolist()))]#Check membership

df.groupby('Noun')['Rating'].mean()


查看完整回答
反對 回復 2023-03-16
  • 1 回答
  • 0 關注
  • 181 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號