1

The output for the function (analysis_data['Date']+ pd.DateOffset(1)).dt.week is

Date             Week
2020-12-26       52   
2020-12-27       53
2020-12-28       53
2020-12-29       53
2020-12-30       53
2020-12-31       53
2021-01-01       53
2021-01-02       53
2021-01-03       1

But i want my dataframe to consider 53 as Week 1 as well

Date             Week
2020-12-26       52   
2020-12-27       1
2020-12-28       1
2020-12-29       1
2020-12-30       1
2020-12-31       1
2021-01-01       1
2021-01-02       1
2021-01-03       2
Harish reddy
  • 431
  • 2
  • 9
  • 1
    just use a conditional? `df['Week'] = np.where((analysis_data['Date']+ pd.DateOffset(1)).dt.week == 53, 1, (analysis_data['Date']+ pd.DateOffset(1)).dt.week)` – Umar.H Feb 11 '21 at 12:31
  • Does this answer your question? [Pandas conditional creation of a series/dataframe column](https://stackoverflow.com/questions/19913659/pandas-conditional-creation-of-a-series-dataframe-column) – Umar.H Feb 11 '21 at 12:31

0 Answers0