Skip to content Skip to sidebar Skip to footer

Calculate Daily Sums Using Python Pandas

I'm trying to calculate daily sums of values using pandas. Here's the test file - http://pastebin.com/uSDfVkTS This is the code I came up so far: import numpy as np import datetime

Solution 1:

You can do it directly in Pandas:

s = pd.read_csv('test', header=None, index_col=0, parse_dates=True)
d = s.groupby(lambda x: x.date()).aggregate(lambda x: sum(x) iflen(x) >= 40else np.nan)

             X.22012-01-01  1128

Solution 2:

Much easier way is to use pd.Grouper:

d = s.groupby(pd.Grouper(freq='1D')).sum()

Post a Comment for "Calculate Daily Sums Using Python Pandas"