![](/img/trans.png)
[英]How can I add a column to a dataframe that is based on another columns value?
[英]How can I find the most common value from a column based on another Columns value in python?
我有一個 dataframe (DF),其中包含以下列:UserID、Country、Arrival_Year、Airport_Code。 每個國家根據用戶 ID 被多次列出。
我想知道數據框中列出的每個國家/地區最常見的到達年份。 我該如何計算?
嘗試使用值計數但沒有得到正確的答案。
嘗試使用 pandas groupby 模式:
df.groupby('Country')['ArrivalYear'].apply(lambda x: x.mode()[0])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.