The Pandas Period property is_leap_year used to determine whether the Period's year belongs to the leap year. It returns a boolean value that specifies Period's year belongs to leap year.
1 import pandas as pd
2
3 period = pd.Period('2020-05-25 12:34', freq = 'H')
4 print('The original period object :')
5 print(period)
6
7 res = period.is_leap_year
8 print('The Period belong to leap year :')
9 print(res)
10
11 period1 = pd.Period('2021-09-22 23:23', freq = 'T')
12 print('The original period object :')
13 print(period1)
14 res1 = period1.is_leap_year
15 print('The Period belong to leap year :')
16 print(res1)
17
18 period2 = pd.Period('2024-01-12', freq = 'S')
19 print('The original period object :')
20 print(period2)
21 res2 = period2.is_leap_year
22 print('The Period belong to leap year :')
23 print(res2)
In the above example, a Period object is created by passing a date as string and frequency. A is_leap_year property is access that determines whether the Period belongs to leap year. The result is assign to the variable that will be printed on console.
1 The original period object :
2 2020-05-25 12:00
3 The Period belong to leap year :
4 True
5
6 The original period object :
7 2021-09-22 23:23
8 The Period belong to leap year :
9 False
10
11 The original period object :
12 2024-01-12 00:00:00
13 The Period belong to leap year :
14 True
Period with individual components
Period with individual components
1 import pandas as pd
2
3
4 period = pd.Period(year = 2024, month = 5, day = 14, hour = 12, freq = 'h')
5 print('The period object with components :')
6 print(period)
7
8 res1 = period.is_leap_year
9 print('The Period belong to leap year :')
10 print(res1)
In the above example, a Period object is created by passing an individual components. A is_leap_year property is access that determines whether the Period belongs to leap year. The result is assign to the variable that will be print.
1 The period object with components :
2 2024-05-14 12:00
3
4 The Period belong to leap year :
5 True
Period with ordinal
1 import pandas as pd
2
3
4 period2 = pd.Period(ordinal = 459036, freq = 'h')
5 print('The period object with ordinal :')
6 print(period2)
7
8 res2 = period2.is_leap_year
9 print('The Period belong to leap year :')
10 print(res2)
In the above example, a Period object is created by passing an ordinal value as parameter. A is_leap_year property is access that determines whether the Period belongs to leap year. The result is assign to the variable that will be print.
1 The period object with ordinal :
2 2022-05-14 12:00
3
4 The Period belong to leap year :
5 False
Related options for your search