[英]Pandas: groupby by date and transform nunique returning too many entries
我正在嘗試在Pandas中進行一個簡單的分組,它不能正常工作:
url='https://raw.githubusercontent.com/108michael/ms_thesis/master/raw_bills'
bills=pd.read_csv(url)
bills.date.nunique()
11
bills.dtypes
date float64
bills object
id.thomas int64
dtype: object
bills[['date', 'bills']].groupby(['date']).bills.transform('nunique')
0 3627
1 7454
2 7454
3 7454
4 3627
5 7454
6 7454
7 3627
8 7454
9 7454
10 3627
11 7454
12 7454
13 7454
14 7454
15 7454
16 3627
17 3627
18 7454
我之前做過這種分組依據,通常效果很好。
有什么建議嗎?
我不確定您要問什么,但是您不想使用:
bills[['date', 'bills']].groupby('date').bills.nunique()
date
2005.0 6820
2006.0 3738
2007.0 7454
2008.0 3627
2009.0 7324
2010.0 3297
2011.0 5787
2012.0 4647
2013.0 5694
2014.0 3211
2015.0 5
Name: bills, dtype: int64
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.