Can';在Python中找不到聚合结果列
“计数”列在哪里?我想您正在寻找Can';在Python中找不到聚合结果列,python,pandas,Python,Pandas,“计数”列在哪里?我想您正在寻找值\u计数 s = pd.Series(["08-10-2017", "08-10-2017", "08-10-2017", "09-10-2017", "09-10-2017", "09-10-2017", "10-10-2017", "10-10-2017", "10-10-2017", "11-10-2017", "11-10-2017", "11-10-2017", "12-10-2017", "12-10-2017", "12-10-2017", "13
值\u计数
s = pd.Series(["08-10-2017", "08-10-2017", "08-10-2017", "09-10-2017", "09-10-2017", "09-10-2017", "10-10-2017", "10-10-2017", "10-10-2017", "11-10-2017", "11-10-2017", "11-10-2017", "12-10-2017", "12-10-2017", "12-10-2017", "13-10-2017", "13-10-2017", "13-10-2017", "14-10-2017", "14-10-2017"])
p = pd.DataFrame(data=s)
p.columns = ['date']
p.groupby('date').agg('count').reset_index().columns
如果你想和groupby打交道
p.date.value_counts()
Out[1095]:
09-10-2017 3
13-10-2017 3
10-10-2017 3
12-10-2017 3
08-10-2017 3
11-10-2017 3
14-10-2017 2
Name: date, dtype: int64
如果你想使用count
p.groupby('date').size()
你能把你得到的结果加起来吗?
p.groupby('date').agg({'date':'count'})
Out[1101]:
date
date
08-10-2017 3
09-10-2017 3
10-10-2017 3
11-10-2017 3
12-10-2017 3
13-10-2017 3
14-10-2017 2