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

從 Pandas 數據框中刪除只有某些列具有相同值的重

Remove duplicate rows from Pandas dataframe where only some columns have the same value(從 Pandas 數據框中刪除只有某些列具有相同值的重復行)
本文介紹了從 Pandas 數據框中刪除只有某些列具有相同值的重復行的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個熊貓數據框如下:

I have a pandas dataframe as follows:

A   B   C
1   2   x
1   2   y
3   4   z
3   5   x

我希望只剩下 1 行在特定列中共享相同值的行.在上面的示例中,我的意思是列 AB.換句話說,如果列 AB 的值在數據框中多次出現,則應該只保留一行(哪一行無關緊要).

I want that only 1 row remains of rows that share the same values in specific columns. In the example above I mean columns A and B. In other words, if the values of columns A and B occur more than once in the dataframe, only one row should remain (which one does not matter).

FWIW:所謂重復行的最大數量(即列AB相同)為2.

FWIW: the maximum number of so called duplicate rows (that is, where column A and B are the same) is 2.

結果應該是這樣的:

A   B   C
1   2   x
3   4   z
3   5   x

A   B   C
1   2   y
3   4   z
3   5   x

推薦答案

使用 drop_duplicates 和參數 subset,為了只保留最后重復的行添加 keep='last':p>

Use drop_duplicates with parameter subset, for keeping only last duplicated rows add keep='last':

df1 = df.drop_duplicates(subset=['A','B'])
#same as
#df1 = df.drop_duplicates(subset=['A','B'], keep='first')
print (df1)
   A  B  C
0  1  2  x
2  3  4  z
3  3  5  x

<小時>

df2 = df.drop_duplicates(subset=['A','B'], keep='last')
print (df2)
   A  B  C
1  1  2  y
2  3  4  z
3  3  5  x

這篇關于從 Pandas 數據框中刪除只有某些列具有相同值的重復行的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: av在线免费不卡 | 亚洲乱码一区二区三区在线观看 | 久久久久精 | 国产农村一级国产农村 | 国产欧美在线播放 | 国产精品99久久久久久动医院 | 午夜一级做a爰片久久毛片 精品综合 | 国产亚洲欧美另类一区二区三区 | www.狠狠干 | 欧美日韩成人影院 | 亚洲一二三区不卡 | 美女爽到呻吟久久久久 | 久久伊人精品 | 国产精品久久久久久久岛一牛影视 | 国产精品美女久久久久久免费 | 成人高清在线视频 | 男人的天堂avav | 网络毛片 | 91精品国产一区二区三区 | 欧美性久久 | 亚洲欧美一区二区三区情侣bbw | a在线视频观看 | 成人中文字幕在线 | www.亚洲区| 国产9久| av中文字幕在线播放 | 99pao成人国产永久免费视频 | 综合久久综合久久 | 中文字幕亚洲视频 | 91精品久久久久久久久久 | 欧美一区2区三区4区公司 | 久久久久久久av | 欧美日韩a | 四虎成人免费视频 | 日韩精品一区二区三区第95 | 成人亚洲精品 | 九九视频在线观看视频6 | 91.xxx.高清在线 | 99久久婷婷国产综合精品电影 | 毛片.com | 亚洲国产自产 |