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

pandas 數據框:基于列和時間范圍的重復

pandas dataframe: duplicates based on column and time range( pandas 數據框:基于列和時間范圍的重復)
本文介紹了 pandas 數據框:基于列和時間范圍的重復的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個(非常簡單的)熊貓數據框,看起來像這樣:

I have a (very simplyfied here) pandas dataframe which looks like this:

df

    datetime             user   type   msg
0  2012-11-11 15:41:08   u1     txt    hello world
1  2012-11-11 15:41:11   u2     txt    hello world
2  2012-11-21 17:00:08   u3     txt    hello world
3  2012-11-22 18:08:35   u4     txt      hello you
4  2012-11-22 18:08:37   u5     txt      hello you

我現在想做的是獲取所有時間戳在 3 秒內的重復消息.期望的輸出是:

What I would like to do now is to get all the duplicate messages which have their timestamp within 3 seconds. The desired output would be:

   datetime              user   type   msg
0  2012-11-11 15:41:08   u1     txt    hello world
1  2012-11-11 15:41:11   u2     txt    hello world
3  2012-11-22 18:08:35   u4     txt      hello you
4  2012-11-22 18:08:37   u5     txt      hello you

沒有第三行,因為它的文本與第一行和第二行相同,但它的時間戳不是3秒以內.

without the third row, as its text is the same as in row one and two, but its timestamp is not within the range of 3 seconds.

我嘗試將列 datetime 和 msg 定義為 duplicate() 方法的參數,但它返回一個空數據幀,因為時間戳不相同:

I tried to define the columns datetime and msg as parameters for the duplicate() method, but it returns an empty dataframe because the timestamps are not identical:

mask = df.duplicated(subset=['datetime', 'msg'], keep=False)

print(df[mask])
Empty DataFrame
Columns: [datetime, user, type, msg, MD5]
Index: []

有沒有一種方法可以為我的日期時間"參數定義一個范圍?為了說明,某事喜歡:

Is there a way where I can define a range for my "datetime" parameter? To illustrate, something like:

mask = df.duplicated(subset=['datetime_between_3_seconds', 'msg'], keep=False)

我們將一如既往地為您提供任何幫助.

Any help here would as always be very much appreciated.

推薦答案

這段代碼給出了預期的輸出

This Piece of code gives the expected output

df[(df.groupby(["msg"], as_index=False)["datetime"].diff().fillna(0).dt.seconds <= 3).reset_index(drop=True)]

我已對數據框的msg"列進行分組,然后選擇該數據框的日期時間"列并使用內置函數 差異.Diff 函數查找該列的值之間的差異.用零填充 NaT 值并僅選擇那些值小于 3 秒的索引.

I have grouped on "msg" column of dataframe and then selected "datetime" column of that dataframe and used inbuilt function diff. Diff function finds the difference between values of that column. Filled the NaT values with zero and selected only those indexes which have values less than 3 seconds.

在使用上述代碼之前,請確保您的數據框按日期時間升序排序.

Before using above code make sure that your dataframe is sorted on datetime in ascending order.

這篇關于 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 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 拍真实国产伦偷精品 | 亚洲精品乱码久久久久v最新版 | 久久噜噜噜精品国产亚洲综合 | 黄色毛片在线观看 | 激情 亚洲| 国产露脸对白88av | 亚洲国产精品久久 | 亚洲一区二区三区四区五区中文 | 韩国欧洲一级毛片 | 91porn国产成人福利 | 国产精品久久久久久52avav | 午夜免费观看网站 | 国产精品乱码一二三区的特点 | 日韩影院一区 | 欧美精三区欧美精三区 | 精品免费av| 日本三级电影在线免费观看 | 欧美日韩专区 | 91观看| 国产中文字幕在线 | 色综合久久88色综合天天 | 精品久久久久久久久亚洲 | 国产精品国产馆在线真实露脸 | 中文字幕一区二区三区在线视频 | 91就要激情 | 国产精品1区 | 精品久久久久久久人人人人传媒 | a级在线免费 | 一区二区三区四区在线免费观看 | 国产精品日产欧美久久久久 | 成人妇女免费播放久久久 | 精品欧美黑人一区二区三区 | 国产精品日韩欧美一区二区三区 | 五月婷六月丁香 | 久久不卡视频 | 日韩成人在线播放 | 久久欧美高清二区三区 | 一级黄片一级毛片 | 日本精品一区二区三区视频 | 日韩免费视频 | 黄色大片在线视频 |