0

anyone here is able to help with this?

start_date = 1-1-2022
end_date = 2-2-2022
delta = end_date - start_dt
freq = 7d
need to generate a column as week number that breaks delta into relevant number of week (freq = 7d) with values as w1, w2, w3,... Note: my dataset is huge with various start & end dates for each user, so it is not feasible to generate 'date_range' and then create a week_number from it.

M.E.R
  • 3
  • 1
  • Welcome to stack overflow. Please [edit] your question to include a [mcve] with sample input data and expected output, as well as code for what you've tried based on your own research and a description of what went wrong with your attempts. See [How to make good pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) for help on creating your data sample. – G. Anderson Mar 02 '22 at 00:04
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Mar 02 '22 at 03:38

1 Answers1

0

You could do as follows to get the unique enumeration of the weeks for your index.

df['week'] = pd.DatetimeIndex(df.index).isocalendar().week
luka1156
  • 181
  • 1
  • 8