Search code examples
pythonpandasgroup-byoffsetpandas-groupby

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.


Solution

  • 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'))