Pandas tseries offsets SemiMonthBegin function is_month_start() in Python
The Pandas tseries offsets SemiMonthBegin function is_month_start() used to determine whether a timestamp occurs on the month start. It returns a boolean value that specifies whether the timestamp occurs at the start of the month.
Syntax
 1 SemiMonthBegin.is_month_start()
dt : It is Timestamp to determine whether the timestamp is at the start of month. It is an instance of datetime.datetime.
is_month_start() function
 1 import pandas as pd
 2 
 3 offset = pd.tseries.offsets.SemiMonthBegin()
 4 
 5 # timestamp at start of month
 6 tstamp = pd.Timestamp(2022, 1, 1)
 7 res = offset.is_month_start(tstamp)
 8 print(f'Does timestamp at start of month : {res}')
 9 
 10 # timestamp not at end of month
 11 tstamp2 = pd.Timestamp(2022, 1, 20)
 12 res2 = offset.is_month_start(tstamp2)
 13 print(f'Does timestamp at start of month : {res2}')
In the above example, a Timestamp objects are created by passing a date that is at a start of the month and second is not at the start of the month. An is_month_start() function is called that determine whether timestamp at starting of the month. The result is assign to the variable that will be printed on console.
Output
 1 Does timestamp at start of month : True
 2 Does timestamp at start of month : False

Example 2

Example 2
 1 import pandas as pd
 2 
 3 tstamp = pd.Timestamp(2022, 9, 1)
 4 print('The timestamp object :', tstamp)
 5 
 6 offset = pd.tseries.offsets.SemiMonthBegin(normalize = True)
 7 res = offset.is_month_start(tstamp)
 8 print(f'Does timestamp at start of month : {res}')
In the above example, a Timestamp objects are created by passing a date that is at a start of the month and SemiMonthBegin with normalize as true. An is_month_start() function is called that determine whether timestamp at starting of the month.
Output
 1 The timestamp object : 2022-09-01 00:00:00
 2 Does timestamp at start of month : True

Example 3

Example 3
 1 import pandas as pd
 2 
 3 tstamp1 = pd.Timestamp(2022, 12, 1)
 4 print('The timestamp object :', tstamp1)
 5 
 6 offset1 = pd.tseries.offsets.SemiMonthBegin(n = 3, normalize = True)
 7 res1 = offset1.is_month_start(tstamp1)
 8 print(f'Does timestamp at start of month : {res1}')
In the above example, a Timestamp objects are created by passing a date that is at a start of the month and SemiMonthBegin with normalize as true and unit frequency as 3. An is_month_start() function is called that determine whether timestamp at starting of the month.
Output
 1 The timestamp object : 2022-12-01 00:00:00
 2 Does timestamp at start of month : True
Privacy Policy
Terms of Service
Disclaimer
Contact us
About us