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

Pandas/Python:如何連接兩個沒有重復的數(shù)據(jù)幀?

Pandas/Python: How to concatenate two dataframes without duplicates?(Pandas/Python:如何連接兩個沒有重復的數(shù)據(jù)幀?)
本文介紹了Pandas/Python:如何連接兩個沒有重復的數(shù)據(jù)幀?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我想將兩個數(shù)據(jù)幀 A、B 連接到一個沒有重復行的新數(shù)據(jù)幀(如果 B 中的行已經(jīng)存在于 A 中,則不要添加):

I'd like to concatenate two dataframes A, B to a new one without duplicate rows (if rows in B already exist in A, don't add):

數(shù)據(jù)框 A:數(shù)據(jù)框 B:

Dataframe A: Dataframe B:

   I    II    I    II
0  1    2     5    6
1  3    1     3    1

新數(shù)據(jù)框:

     I    II
  0  1    2
  1  3    1
  2  5    6

我該怎么做?

推薦答案

最簡單的方法是只進行連接,然后刪除重復項.

The simplest way is to just do the concatenation, and then drop duplicates.

>>> df1
   A  B
0  1  2
1  3  1
>>> df2
   A  B
0  5  6
1  3  1
>>> pandas.concat([df1,df2]).drop_duplicates().reset_index(drop=True)
   A  B
0  1  2
1  3  1
2  5  6

reset_index(drop=True)是修復concat()drop_duplicates()之后的索引.沒有它,您將擁有 [0,1,0] 的索引,而不是 [0,1,2].如果不立即重置,這可能會導致對該 dataframe 的進一步操作出現(xiàn)問題.

The reset_index(drop=True) is to fix up the index after the concat() and drop_duplicates(). Without it you will have an index of [0,1,0] instead of [0,1,2]. This could cause problems for further operations on this dataframe down the road if it isn't reset right away.

這篇關于Pandas/Python:如何連接兩個沒有重復的數(shù)據(jù)幀?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區(qū)域周圍繪制一個矩形)
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(根據(jù)文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 国产在线观看 | av大片| 日韩综合在线 | 黄色大片在线视频 | 97超碰站 | 国产三级在线观看播放 | www成年人视频 | 91精品国产91久久综合桃花 | 波多野结衣中文字幕一区二区三区 | 日韩视频在线免费观看 | 欧美亚洲日本 | 国产91网址 | 欧美色性| 欧美日韩一卡二卡 | 精品国产第一区二区三区 | 综合二区 | 中文字幕高清 | 精品国产视频 | 99久久免费精品国产男女高不卡 | 国产精品99久久久久久久久 | 久久精品视频9 | 国产精品久久久久久久久免费樱桃 | 精品久久视频 | 国产在线观看一区二区三区 | 国产精品入口久久 | 久久中文网| 久久久久久久久久久久久久久久久久久久 | 日本福利一区 | 亚洲一区二区三区免费观看 | 一区二区三区免费 | 精品国产第一区二区三区 | 欧美日韩一区在线观看 | 91精品国产91综合久久蜜臀 | 又黑又粗又长的欧美一区 | 91高清在线视频 | 午夜网站视频 | 美女一区二区在线观看 | 欧美日韩最新 | 欧美日韩亚洲一区 | 99精品国产一区二区青青牛奶 | 日韩久久精品视频 |