The Pandas tseries offsets Week function is_year_start() used to determine whether a timestamp occurs on the year start. It returns a boolean value that specifies whether timestamp occurs at the starting of year.
1 import pandas as pd
2
3 offset = pd.tseries.offsets.Week()
4
5 tstamp = pd.Timestamp(2022, 1, 1)
6 res = offset.is_year_start(tstamp)
7 print(f'The timestamp occurs at start of year : {res}')
8
9 tstamp1 = pd.Timestamp(2022, 2, 18)
10 res1 = offset.is_year_start(tstamp1)
11 print(f'The timestamp occurs at start of year : {res1}')
In the above example, a Timestamp object is created by passing a date value. A is_year_start() is called that determine whether timestamp occurs at the start of year. The result is assign to the variable that will be printed on console.
1 The timestamp occurs at start of year : True
2 The timestamp occurs at start of year : False
Example 2
1 import pandas as pd
2
3 tstamp = pd.Timestamp(2023, 1, 1)
4 print('The timestamp object :', tstamp)
5
6 offset = pd.tseries.offsets.Week(normalize = True)
7 res = offset.is_year_start(tstamp)
8 print(f'The timestamp occurs at start of year : {res}')
In the above example, a Timestamp object is created by passing a date value and a Week object with normalize as true. A is_year_start() is called that determine whether timestamp occurs at the start of year.
1 The timestamp object : 2023-01-01 00:00:00
2 The timestamp occurs at start of year : True
Example 3
1 import pandas as pd
2
3 tstamp1 = pd.Timestamp(2023, 1, 31)
4 print('The timestamp object :', tstamp1)
5
6 offset1 = pd.tseries.offsets.Week(weekday = 2, n = 3, normalize = True)
7 res1 = offset1.is_year_start(tstamp1)
8 print(f'The timestamp occurs at start of year : {res1}')
In the above example, a Timestamp object is created by passing a date value and a Week object with normalize as true and unit frequency as 3. A is_year_start() is called that determine whether timestamp occurs at the start of year.
1 The timestamp object : 2023-01-31 00:00:00
2 The timestamp occurs at start of year : False
Related options for your search