Reputation: 5347
import copy
head6= copy.deepcopy(df)
closed_day = head6[["DATEn","COUNTn"]]\
.groupby(head6['DATEn']).sum()
print closed_day.head(10)
Output:
COUNTn
DATEn
06-29-13 11326823
06-30-13 5667746
07-01-13 8694140
07-02-13 7275701
07-03-13 9948824
07-04-13 1072542591
07-05-13 7867611
07-06-13 4733018
07-07-13 4838404
07-08-13 42962814
Now what if I want to find if COUNTn
has any zeros and I want to return corresponding day? I've written something like this but I'm getting an error saying my df doesn't have any column called COUNTn
ndf = closed_day[["DATEn","COUNTn"]][closed_day.COUNTn == 0]
print ndf.head(1)
Upvotes: 0
Views: 1108
Reputation: 36545
After the groupby, COUNTn is converted into a Series, which doesn't have columns (it's just a single column). If you want to keep it as a dataframe, as your code is expecting, use groupby(grouper, as_index=False)
.
Upvotes: 1