Python Articles

Page 298 of 855

Python Pandas - Get the quarter of the year from Period object

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 543 Views

To get the quarter of the year component of a Period object, use the period.quarter property. This property returns an integer from 1 to 4 representing which quarter the period falls into. Creating Period Objects First, let's import pandas and create Period objects ? import pandas as pd # Create Period objects with different formats period1 = pd.Period("2020-02-27 08:32:48") period2 = pd.Period(freq="M", year=2021, month=8, day=16, hour=2, minute=35) print("Period1:", period1) print("Period2:", period2) Period1: 2020-02-27 08:32:48 Period2: 2021-08 Getting Quarter Information Use the .quarter property to extract quarter information from ...

Read More

Python Pandas - Get the month of the year component of the Period

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 361 Views

To get the month of the year component of the Period, use the period.month property. The Pandas Period represents a period of time and provides various properties to extract date components. Syntax period.month Creating Period Objects First, let's create Period objects using different methods ? import pandas as pd # Creating Period objects period1 = pd.Period("2020-09-23 05:55:30") period2 = pd.Period(freq="M", year=2021, month=8, day=16, hour=2, minute=35) # Display the Period objects print("Period1...", period1) print("Period2...", period2) The output of the above code is ? Period1... 2020-09-23 05:55:30 ...

Read More

Python Pandas - Get the minute of the hour component of the Period

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 149 Views

In Pandas, you can extract the minute component from a Period object using the period.minute property. This property returns the minute value (0-59) from the Period's datetime representation. Syntax period.minute Where period is a Pandas Period object containing datetime information. Creating Period Objects First, let's create Period objects with different datetime formats ? import pandas as pd # Create Period from string representation period1 = pd.Period("2020-09-23 05:55:30") # Create Period using individual components period2 = pd.Period(freq="T", year=2021, month=7, day=16, hour=2, minute=35) print("Period1:", period1) print("Period2:", period2) ...

Read More

Python Pandas - Check whether the year is a leap year from the Period object

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 274 Views

To check whether the year is a leap year from the Period object, use the period.is_leap_year property. This property returns True if the year in the Period is a leap year, otherwise False. Syntax period.is_leap_year Creating Period Objects First, import pandas and create Period objects to work with ? import pandas as pd # Create Period objects with different years period1 = pd.Period("2020-09-23 05:55:30") period2 = pd.Period(freq="Y", year=2021, month=7, day=16, hour=2, minute=35) # Display the Period objects print("Period1...", period1) print("Period2...", period2) Period1... 2020-09-23 05:55:30 Period2... ...

Read More

Python Pandas - Get the hour of the day component of the Period

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 162 Views

To get the hour of the day component of the Period, use the period.hour property. This property returns an integer value representing the hour component (0-23) of a Pandas Period object. Creating Period Objects First, let's import pandas and create Period objects with datetime information ? import pandas as pd # Creating Period objects with datetime strings period1 = pd.Period("2020-09-23 05:55:30") period2 = pd.Period(freq="H", year=2021, month=7, day=16, hour=2, minute=35) print("Period1:", period1) print("Period2:", period2) Period1: 2020-09-23 05:55:30 Period2: 2021-07-16 02:00 Extracting Hour Components Use the hour property to extract ...

Read More

Python Pandas - Return the string alias of the Time series frequency applied on the given Period object

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 179 Views

To return the string alias of the Time series frequency applied on the given Period object, use the period.freqstr property. This property provides a human-readable representation of the frequency used by the Period object. What is period.freqstr? The freqstr property returns a string alias that describes the frequency of the Period object. It shows information like the base frequency (Second, Day, Year) and any additional parameters. Creating Period Objects First, let's create Period objects with different frequencies ? import pandas as pd # Create Period objects with different frequencies period1 = pd.Period("2020-09-23 03:55:20") ...

Read More

Python Pandas - Find the end time for the given Period object

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 252 Views

To find the end time for the given Period object, use the period.end_time property. This property returns a Timestamp representing the end time of the period. Syntax period.end_time Returns: Timestamp representing the end time of the period Creating Period Objects First, let's import pandas and create Period objects with different frequencies ? import pandas as pd # Create Period objects with different frequencies period1 = pd.Period("2020-09-23 03:55:20") period2 = pd.Period(freq="T", year=2021, month=2, day=14, hour=2, minute=35) print("Period1:", period1) print("Period2:", period2) Period1: 2020-09-23 03:55:20 Period2: 2021-02-14 02:35 ...

Read More

Python Pandas - Get the frequency for the given Period object

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 516 Views

To get the frequency for the given Period object, use the period.freq property. The pandas.Period represents a period of time with an associated frequency that determines the resolution of the time period. Creating Period Objects First, import pandas and create Period objects with different frequencies ? import pandas as pd # Create Period objects with different frequencies period1 = pd.Period("2020-09-23 03:55:20") period2 = pd.Period(freq="T", year=2021, month=2, day=14, hour=2, minute=35) print("Period1:", period1) print("Period2:", period2) Period1: 2020-09-23 03:55:20 Period2: 2021-02-14 02:35 Getting Frequency Information Use the .freq property to retrieve ...

Read More

Python Pandas - Form the Union of two Index objects

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 201 Views

To form the Union of two Index objects, use the index1.union(index2) method in Pandas. The union operation combines all unique elements from both indexes and returns them in sorted order. Syntax index1.union(index2, sort=None) Parameters The union() method accepts the following parameters ? index2 − The second Index object to union with sort − Whether to sort the result (default: None, which sorts if possible) Creating Index Objects First, let's create two Pandas Index objects ? import pandas as pd # Creating two Pandas index index1 = ...

Read More

Python Pandas - Get the total number of days of the month that the Period falls in

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 755 Views

To get the total number of days of the month that a Period falls in, use the period.daysinmonth property in Pandas. This property returns an integer representing the total days in that specific month and year. Syntax period.daysinmonth Where period is a Pandas Period object. Creating Period Objects First, let's create Period objects to demonstrate the daysinmonth property ? import pandas as pd # Create Period objects using different methods period1 = pd.Period("2020-09-23") period2 = pd.Period(freq="D", year=2021, month=2, day=14, hour=2, minute=35) period3 = pd.Period("2020-02-15") # Leap year February ...

Read More
Showing 2971–2980 of 8,546 articles
« Prev 1 296 297 298 299 300 855 Next »
Advertisements