0

I am trying to lineup date values in my df to bi-weekly format. Lets have 1st 2-weeks interval starts at 1/1/2021, the second interval starts at 1/14/2021 if df value belongs to 1st interval, i would like to see 1st interval value.

df = pd.date_range(start='1/1/2021', periods=45)
df.to_period('2W').start_time

even if i set "2W" argument, it is one-week anyway. but if I am using groupby function with "2W" - it works fine. Can you please help me to find the solution?

My ANSWER: I take week' number and converts to odd numbers. that gives me chance to agreegate df by 2 weeks interval. Hope, it will help to someone :)

df['registered_2W'] = (lambda x: x+(x+1)%2)(df['registered'].dt.strftime("%V").astype(int)) 

OcMaRUS
  • 329
  • 3
  • 13
  • Does this help: `df = pd.date_range(start='1/1/2021', periods=45, freq='2W-FRI')` ? – jch Jun 25 '21 at 22:43
  • .date_range - it is just an example to fill the df with values. Real df exists and i have to change existing datetime values. – OcMaRUS Jun 25 '21 at 22:47
  • Maybe hack your way in with `.dt.week/2`? Then go back the other direction to get the date? Ugly I know. I don't see a good answer at this point. Same problem you are having. – jch Jun 25 '21 at 23:16
  • @jch - that was I am using as a solution: df['registered_2W'] = (lambda x: x+(x+1)%2)(df['registered'].dt.strftime("%V").astype(int)) – OcMaRUS Jul 06 '21 at 09:17

0 Answers0