查找 Python 中每个名称的计数、最早日期和最晚日期

Finding the count, earliest date and latest date for each name in Python

假设我有如下数据,其中包含名称、class 和日期

Name    class   Date
A   7th grade   1/1/2016
A   7th grade   1/2/2016
A   7th grade   1/3/2016
A   7th grade   1/4/2016
A   7th grade   1/5/2016
A   7th grade   1/6/2016
A   7th grade   1/7/2016
B   8th grade   1/8/2016
B   8th grade   1/9/2016
B   8th grade   1/10/2016
C   9th grade   1/11/2016
C   9th grade   1/12/2016
C   9th grade   1/13/2016
C   9th grade   1/14/2016
C   9th grade   1/15/2016
C   9th grade   1/16/2016
C   9th grade   1/17/2016
C   9th grade   1/18/2016
C   9th grade   1/19/2016
C   9th grade   1/20/2016
C   9th grade   1/21/2016
C   9th grade   1/22/2016

我正在寻找一个输出,它会给我每个名字的值计数、它们各自的等级以及最早日期和最晚日期。我的输出是,

Name grade   count earlydate latestdate
A   7thgrade   7    1/1/2016  1/7/2016
B   8th grade  3    1/8/2016  1/10/2016
C   9th grade  12   1/11/2016 1/22/2016

我可以找到每个名字的计数,

data.groupby('name','grade').count()
or
data.groupby('name','grade').size()

但无法在日期列中找到最早的日期和最晚的日期。

谁能帮我解决这个问题?

Max and Min date in pandas groupby

可能是这样的:

data.groupby('name','grade').agg({'date' : [np.min, np.max]}).count()