Pandas tseries offsets WeekOfMonth property normalize in Python
The Pandas tseries offsets WeekOfMonth property normalize represents whether to shift the start of the next offset as first week of the month with midnight. It returns a boolean value that specifies whether to shift first week of month and midnight.
Syntax
 1 WeekOfMonth.normalize
normalize property
 1 import pandas as pd
 2 
 3 offset = pd.tseries.offsets.WeekOfMonth()
 4 res = offset.normalize
 5 print(f'The WeekOfMonth normalize property : {res}')
In the above example, a WeekOfMonth object is created and a normalize property is access that returns a boolean False. If normalize parameter is not specified, the default value will be False. The result is assign to the variable that will be printed on console.
Output
 1 The WeekOfMonth normalize property : False

WeekOfMonth with timestamp and normalize

WeekOfMonth with timestamp and normalize
 1 import pandas as pd
 2 
 3 tstamp = pd.Timestamp(2022, 1, 14, 12, 35)
 4 offset = pd.tseries.offsets.WeekOfMonth(normalize = True)
 5 res = tstamp + offset
 6 print(f'The normalize timestamp : {res}')
In the above example, a WeekOfMonth object is created by passing a normalize parameter as True. A timestamp object is created with datetime value. An offset is added to timestamp that returns timestamp with next offset as first day of the month with midnight.
Output
 1 The normalize timestamp : 2022-02-07 00:00:00

Example 2

Example 2
 1 import pandas as pd
 2 
 3 tstamp = pd.Timestamp(2023, 12, 1, 12, 23)
 4 print('The timestamp object :', tstamp)
 5 
 6 offset = pd.tseries.offsets.WeekOfMonth(normalize = True)
 7 res = tstamp + offset
 8 print(f'The normalize timestamp : {res}')
In the above example, a WeekOfMonth object is created without unit frequency and a normalize property that returns timestamp with next offset as first day of the month with midnight. If normalize parameter is not specified, the default value will be False.
Output
 1 The timestamp object : 2023-12-01 12:23:00
 2 The normalize timestamp : 2023-12-04 00:00:00

Example 3

Example 3
 1 import pandas as pd
 2 
 3 tstamp1 = pd.Timestamp(2023, 1, 31, 11, 22)
 4 print('The timestamp object :', tstamp1)
 5 
 6 offset1 = pd.tseries.offsets.WeekOfMonth(weekday = 2, n = 3, normalize = True)
 7 res1 = tstamp1 + offset1
 8 print(f'The normalize timestamp : {res1}')
In the above example, a WeekOfMonth object is created with unit frequency and a normalize property that returns timestamp with next offset as first day of the month with midnight. If normalize parameter is not specified, the default value will be False.
Output
 1 The timestamp object : 2023-01-31 11:22:00
 2 The normalize timestamp : 2023-04-05 00:00:00
Privacy Policy
Terms of Service
Disclaimer
Contact us
About us