Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All days instead of business days? #44

Closed
ghost opened this issue May 6, 2011 · 4 comments
Closed

All days instead of business days? #44

ghost opened this issue May 6, 2011 · 4 comments

Comments

@ghost
Copy link

ghost commented May 6, 2011

Hi,

I am very new to github and miss a discussion board for pandas. Not sure if issues is the right place for my question, so feel free to delete it, but please point to the right place for questions.

The question: I need to aggregate hourly time series to the daily scale, that would include all days, 7 per week. Currently i find only bday class in datetools:

daily_ts = ts.groupby(lambda x: datetools.bday(x)).aggregate(np.nansum)

But bday will skip weekends. datetools.day seem to return timeseries with the same time resolution.
How to include weekend days?

Many thanks for developing pandas, it's truly nice, and really fast, even when working with large datasets!

@ghost
Copy link
Author

ghost commented May 6, 2011

For the moment i solved the problem by copying creating a calendar days class, CDay, which is a copy of BDay, but with 7 days in the week.

But i guess i am just missing a nicer solution..

@wesm
Copy link
Member

wesm commented May 6, 2011

No need for a calendar days class for this purpose. I think you want:

from pandas.core.datetools import normalize_date
daily_ts = ts.groupby(normalize_date).aggregate(np.nansum)

# alternately
daily_ts = ts.groupby(normalize_date).aggregate(Series.sum)

I actually plan to make this work (right now it does, but not with NaNs...making a note to make the change to the code soon):

daily_ts = ts.groupby(normalize_date).sum()

For converting to calendar day frequency, ts.asfreq(datetools.day) will do

Hope this helps

@wesm wesm closed this as completed May 6, 2011
@ghost
Copy link
Author

ghost commented May 6, 2011

Nice, that's what i was looking for!

Thanks a lot,
Mikhail

@ghost
Copy link
Author

ghost commented May 16, 2011

Wes,

I can't find the answer in the documentation, thus asking here again:

stijnvanhoey pushed a commit to stijnvanhoey/pandas that referenced this issue Dec 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant