久久久久久久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 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 久久久天天 | 美女黄色在线观看 | 武道仙尊动漫在线观看 | 99伊人网| 嫩草视频在线免费观看 | 国产成人叼嘿视频在线观看 | 色视频网站| 欧美视频在线观看 | 91一区二区| 午夜视频一区二区三区 | 国产精品大片在线观看 | 亚洲国产精品人人爽夜夜爽 | caoporn国产精品免费公开 | 综合精品| 精品国产一区二区在线 | 毛片免费看的 | 日韩有码一区 | 一级免费看片 | 精品国产乱码久久久久久丨区2区 | 国产日韩欧美精品一区二区 | 久久最新精品视频 | 国产高清在线精品一区二区三区 | 国产女人与拘做视频免费 | www.中文字幕.com | 免费爱爱视频 | 午夜影院 | 免费在线观看成人 | 久久久综合精品 | 久久国产精品-国产精品 | 日本一区视频在线观看 | 男女久久久 | 欧美成人精品一区二区男人看 | 欧美色综合一区二区三区 | 国产精品视频一 | 精品国产1区2区3区 一区二区手机在线 | 在线观看 亚洲 | 欧美一级片中文字幕 | 成人av片在线观看 | 亚洲国产成人精品女人久久久 | 中文字幕av网 | 不卡在线一区 |