[英]By changing values in one column based on condition in another column returns error
[英]Returning max value in one column based on changing condition in another column
我有一個看起來像這樣的數據集:
| | season | stormid | vmax |
|0 | 1970 | SH071970 | 1 |
|1 | 1970 | SH071971 | 6 |
|2 | 1970 | SH071970 | 3 |
|3 | 1970 | SH071971 | 9 |
我想為每個可以作為附加列添加到另一個 dataframe 的唯一 stormid 返回 vmax 的最大值。
到目前為止我已經嘗試過
df['vmax'] = df['stormid']['vmax'].max()
沒有運氣。
是否可以編寫一個 for 循環來遍歷 stormid(我已將其存儲在另一個數據框中)並從 vmax 列返回最大值?
使用groupby
。 示例代碼在這里。
df.groupby('stromid')['vmax'].max()
它返回 pandas 索引為 stormid 的系列,根據 stromid,值為 vmax 的最大值
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.