2016-02-26 68 views
0

假設,如果我有類似下面的數據,有姓名,班級和日期尋找伯爵,最早日期和最晚日期爲每名在Python

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() 

但無法找到日期列內早日和最新日期。

任何人都可以幫助我嗎?

+0

什麼樣的數據庫您使用的是?嘗試在sql – clemkoa

+0

中使用連接和MIN/MAX函數我將它作爲一個python數據框。需要在python – haimen

+0

http://stackoverflow.com/questions/23178129/getting-min-and-max-dates-from-a-pandas-dataframe – clemkoa

回答