久久久久久久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 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 精品视频成人 | 欧美电影免费观看 | 欧美99| 亚洲经典一区 | 91精品国产一区二区三区动漫 | 亚洲一区二区三区四区五区午夜 | 一级做a毛片 | 日日骚网| 国产精品乱码一二三区的特点 | 一片毛片 | 91视频一区二区三区 | 亚洲国产精品一区二区久久 | 久久最新| 毛片a区 | 99视频在线播放 | 激情欧美一区二区三区中文字幕 | 最新国产视频 | 色婷婷久久久亚洲一区二区三区 | 国产激情精品视频 | 男人的天堂久久 | 亚洲精品国产区 | 国产成人精品免费视频大全最热 | 一级欧美 | 国产免费一区二区 | 韩日一区 | 国产高清一区二区三区 | 国产成在线观看免费视频 | 成人精品久久 | 6996成人影院网在线播放 | 亚洲高清在线观看 | 人人干超碰 | 欧洲精品视频一区 | 草久久| 国产精品无码专区在线观看 | 日韩一级免费看 | 欧美日韩中文国产一区发布 | 美女国内精品自产拍在线播放 | 狠狠骚 | 欧美精品在欧美一区二区少妇 | 国产剧情一区 | 日韩国产在线 |