久久久久久久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 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 成人在线日韩 | 五月网婷婷 | 亚洲欧美国产视频 | 国产亚洲人成a在线v网站 | 网色| 成人av播放| 中文字幕亚洲精品 | 国产日韩精品在线 | 91在线视频免费观看 | 国产免费播放视频 | 日韩精品一区二区三区在线 | 久久久久久免费毛片精品 | 欧美久久一区二区 | 国产精品久久精品 | 国产高清精品一区 | 人妖无码 | 国产精品区二区三区日本 | 中文字幕日韩在线观看 | www.99精品 | 国产精品欧美一区二区 | 国产伦一区二区三区久久 | 中文字幕在线二区 | 久久久久久久久中文字幕 | 亚洲一区免费在线 | 精品国产一区二区三区久久狼黑人 | 日韩在线精品强乱中文字幕 | 男女一区二区三区 | 日本久久久久久久久 | 久久精品一区二区 | 国产在线观看不卡一区二区三区 | 99热在线免费| 欧美一区二区三区在线播放 | 亚洲精品久久久一区二区三区 | 97国产精品视频人人做人人爱 | 久久网国产 | 欧美在线观看一区 | 久久久xxx| 别c我啊嗯国产av一毛片 | 欧美在线色视频 | 九色视频网站 | 成人午夜在线 |