Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pandas groupby offsets different start

I have a simple offset question that I cannot seem to find the answer for in the other previous posts. I am trying to groupby weeks, but the default df.groupby(pd.TimeGrouper('1W')) gives me the groupby starting on Sunday.

Say for instance I want this groupby to start on Tuesday. I tried to naively add pd.DateOffset(days=2) as an additional argument but that did not seem to work.

like image 752
Bobe Kryant Avatar asked Jan 20 '17 14:01

Bobe Kryant


1 Answers

Offset strings can include a component that specifies when the type of period should start.

In your case, you want W-Tue

df.groupby(pd.TimeGrouper('W-Tue'))
like image 81
piRSquared Avatar answered Oct 28 '22 07:10

piRSquared