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

刪除 *NEARLY* 重復的觀察 - Python

Removing *NEARLY* Duplicate Observations - Python(刪除 *NEARLY* 重復的觀察 - Python)
本文介紹了刪除 *NEARLY* 重復的觀察 - Python的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試刪除 pandas DataFrame 中的一些觀察結果,其中相似性幾乎為 100%,但不完全一致.見下圖:

I am attempting to remove some observations in a pandas DataFrame where the similarities are ALMOST 100% but not quite. See frame below:

注意John"、Mary"和Wesley"是如何出現的具有幾乎相同的觀察結果,但有一列不同.真實數據集有 15 列和 215,000 多個觀測值.在我可以直觀驗證的所有情況下,相似之處同樣是:在 15 列中,其他觀察每次最多匹配 14 列.為了項目的目的,我決定刪除重復的觀察結果(并將它們存儲到另一個 DataFrame 中,以防我的老板要求查看它們).

Notice how "John", "Mary", and "Wesley" have nearly identical observations, but have one column being different. The real data set has 15 columns, and 215,000+ observations. In all of the cases I could visually verify, the similarities were likewise: out of 15 columns, the other observation would match up to 14 columns, every time. For the purpose of the project I have decided to remove the repeated observations (and store them into another DataFrame just in case my boss asks to see them).

我顯然已經想到了 remove_duplicates(keep='something'),但這行不通,因為觀察結果并不完全相似.有沒有人遇到過這樣的問題?有什么補救辦法嗎?

I have evidently thought of remove_duplicates(keep='something'), but that would not work since the observations are not ENTIRELY similar. Has anyone ever encounter such an issue? Any idea on a remedy?

推薦答案

關于列子集的簡單循環怎么樣:

What about a simple loop over subset of columns :

import pandas as pd

df = pd.DataFrame(
        [
            ['John', 45, 85000, 'DC'],
            ['Netcha', 25, 48000, 'NYC'],
            ['Mary', 45, 85000, 'DC'],
            ['Wesley', 36, 72500, 'LA'],
            ['Porter', 22, 98750, 'Seattle'],
            ['John', 45, 105500, 'DC'],
            ['Mary', 28, 85000, 'DC'],
            ['Wesley', 36, 72500, 'Boston'],
        ], 
        columns=['Name', 'Age', 'Salary', 'City'])

cols = df.columns.tolist()
cols.remove('Name')

for col in cols:
    observed_cols = df.drop(col, axis=1).columns.tolist()
    df.drop_duplicates(observed_cols, keep='first', inplace=True)

print(df)

返回:

     Name  Age  Salary     City
0    John   45   85000       DC
1  Netcha   25   48000      NYC
2    Mary   45   85000       DC
3  Wesley   36   72500       LA
4  Porter   22   98750  Seattle

這篇關于刪除 *NEARLY* 重復的觀察 - Python的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 久久精品一区 | 俺去俺来也www色官网cms | 99久久精品视频免费 | 成人日韩精品 | 在线资源视频 | 麻豆国产一区二区三区四区 | 美女视频黄的 | 91在线视频观看免费 | 精精国产xxxx视频在线播放 | 三级视频国产 | 亚洲第一区久久 | 亚洲欧美精品 | 免费国产网站 | 夜夜撸av| 天天射中文 | 久久精品视频网站 | 久久高清| 久久亚洲精品视频 | 国产免费黄网 | 亚洲国产高清高潮精品美女 | 日韩中文字幕在线视频 | 亚洲欧美激情网 | 你懂的国产| 日日夜夜草 | 九九热在线视频 | 国产精品成人在线 | 久久中文网 | 一级特黄网站 | 亚洲在线 | 精品99久久久久久 | 久草中文网 | 91亚洲国产亚洲国产 | 欧美精品在线免费 | 国产色在线 | 国产精品一区二区三区久久久 | av日韩高清| 日韩在线国产精品 | 日韩高清www | 秋霞电影院午夜伦 | 欧美色影院 | 欧美一级欧美三级在线观看 |