久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

按 A 列刪除重復項,保留 B 列中值最高的行

Remove duplicates by columns A, keeping the row with the highest value in column B(按 A 列刪除重復項,保留 B 列中值最高的行)
本文介紹了按 A 列刪除重復項,保留 B 列中值最高的行的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我在 A 列中有一個包含重復值的數據框.我想刪除重復項,將具有最高值的行保留在 B 列中.

I have a dataframe with repeat values in column A. I want to drop duplicates, keeping the row with the highest value in column B.

所以這個:

A B
1 10
1 20
2 30
2 40
3 10

應該變成這樣:

A B
1 20
2 40
3 10

我猜可能有一種簡單的方法可以做到這一點——可能就像在刪除重復項之前對 DataFrame 進行排序一樣簡單——但我不太了解 groupby 的內部邏輯,無法弄清楚.有什么建議嗎?

I'm guessing there's probably an easy way to do this—maybe as easy as sorting the DataFrame before dropping duplicates—but I don't know groupby's internal logic well enough to figure it out. Any suggestions?

推薦答案

這是最后一個.雖然不是最大值:

This takes the last. Not the maximum though:

In [10]: df.drop_duplicates(subset='A', keep="last")
Out[10]: 
   A   B
1  1  20
3  2  40
4  3  10

你也可以這樣做:

In [12]: df.groupby('A', group_keys=False).apply(lambda x: x.loc[x.B.idxmax()])
Out[12]: 
   A   B
A       
1  1  20
2  2  40
3  3  10

這篇關于按 A 列刪除重復項,保留 B 列中值最高的行的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 高清久久 | 在线成人福利 | 国产欧美视频一区 | 91亚洲精品国偷拍自产在线观看 | 最新黄色毛片 | 色婷婷av777 av免费网站在线 | 亚洲国产一区二区三区 | 精品乱码一区二区 | 日韩欧美中文 | 国产成人99久久亚洲综合精品 | 国产精品久久久久久久久免费高清 | 91精品国产91 | 超碰免费在 | 欧美福利在线 | 综合五月婷 | 玖玖国产| 九色 在线 | 亚洲综合在 | 午夜精品久久久久久久久久久久 | 91在线电影 | 国产乱码精品一品二品 | 国产女人第一次做爰毛片 | 91国内在线观看 | 精品一区二区三区不卡 | 久久精品二区 | 一级国产精品一级国产精品片 | 精品精品视频 | 日韩av手机在线观看 | 成人免费视频 | 密乳av | av天天爽| 在线观看中文字幕视频 | 亚洲电影免费 | 亚洲大片| 精品久久久久久久 | 欧美精品在线一区 | 国产精品久久久久久久久久三级 | 亚洲精品不卡 | 国产欧美日韩一区二区三区 | 免费观看www7722午夜电影 | 国产激情三区 |