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

pandas :在 groupby 'date' 中刪除重復項

pandas: drop duplicates in groupby #39;date#39;( pandas :在 groupby date 中刪除重復項)
本文介紹了 pandas :在 groupby 'date' 中刪除重復項的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

在下面的數據框中,我想消除重復的 cid 值,以便 df.groupby('date').cid.size() 的輸出匹配df.groupby('date').cid.nunique() 的輸出.

In the dataframe below, I would like to eliminate the duplicate cid values so the output from df.groupby('date').cid.size() matches the output from df.groupby('date').cid.nunique().

我看過這個 post 但它似乎沒有解決問題的可靠方法.

I have looked at this post but it does not seem to have a solid solution to the problem.

df = pd.read_csv('https://raw.githubusercontent.com/108michael/ms_thesis/master/crsp.dime.mpl.df')

df.groupby('date').cid.size()

date
2005       7
2006     237
2007    3610
2008    1318
2009    2664
2010     997
2011    6390
2012    2904
2013    7875
2014    3979

df.groupby('date').cid.nunique()

date
2005      3
2006     10
2007    227
2008     52
2009    142
2010     57
2011    219
2012     99
2013    238
2014    146
Name: cid, dtype: int64

我嘗試過的事情:

  1. df.groupby([df['date']]).drop_duplicates(cols='cid') 給出此錯誤:AttributeError: Cannot access callable attribute 'drop_duplicates' of 'DataFrameGroupBy' 對象,嘗試使用 'apply' 方法
  2. df.groupby(('date').drop_duplicates('cid')) 給出此錯誤:AttributeError: 'str' object has no attribute 'drop_duplicates'
  1. df.groupby([df['date']]).drop_duplicates(cols='cid') gives this error: AttributeError: Cannot access callable attribute 'drop_duplicates' of 'DataFrameGroupBy' objects, try using the 'apply' method
  2. df.groupby(('date').drop_duplicates('cid')) gives this error: AttributeError: 'str' object has no attribute 'drop_duplicates'

推薦答案

您不需要 groupby 刪除基于幾列的重復項,您可以指定一個子集:

You don't need groupby to drop duplicates based on a few columns, you can specify a subset instead:

df2 = df.drop_duplicates(["date", "cid"])
df2.groupby('date').cid.size()
Out[99]: 
date
2005      3
2006     10
2007    227
2008     52
2009    142
2010     57
2011    219
2012     99
2013    238
2014    146
dtype: int64

這篇關于 pandas :在 groupby 'date' 中刪除重復項的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 国产午夜精品福利 | 日本aa毛片a级毛片免费观看 | 亚洲va欧美va天堂v国产综合 | 国产日韩精品一区二区三区 | 91在线精品秘密一区二区 | 久久免费观看一级毛片 | 亚洲欧美视频一区 | 亚洲 欧美 日韩在线 | 亚洲一区二区在线播放 | 欧美在线视频一区二区 | 国产精品国产精品国产专区不蜜 | 99re视频这里只有精品 | 在线观看中文字幕 | 欧美a级成人淫片免费看 | 日本在线播放一区二区 | 亚洲一区二区三区视频 | 成人精品一区 | 日本 欧美 三级 高清 视频 | 韩国成人在线视频 | 91国内产香蕉 | av大片| 国产精品免费看 | 日韩一区二区三区视频在线播放 | 久草网站 | 婷婷福利视频导航 | 香蕉久久久 | 伊人一区 | 91精品久久久久久久久中文字幕 | 一区二区三区欧美在线观看 | 啪啪网页 | 国产区视频在线观看 | 干干干日日日 | 亚洲欧美视频在线观看 | 91传媒在线观看 | 亚洲品质自拍视频网站 | 五月激情综合 | 中文一区 | 久久久性色精品国产免费观看 | 综合九九 | 久久久久91 | 91av在线视频观看 |