Articles on Trending Technologies

Technical articles with clear explanations and examples

Python Pandas - Format the Period object and display Quarter

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 2K+ Views

To format the Period object in Pandas, use the period.strftime() method. To display the quarter, set the parameter as Q%q which shows the quarter number (Q1, Q2, Q3, or Q4). Creating a Period Object First, import pandas and create a Period object with specific date and time components ? import pandas as pd # Create a Period object with second frequency period = pd.Period(freq="S", year=2021, month=9, day=18, hour=8, minute=20, second=45) # Display the Period object print("Period...") print(period) Period... 2021-09-18 08:20:45 Formatting to Display Quarter Use strftime() with 'Q%q' ...

Read More

Python Pandas - Format and return the string representation of the Period object

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 1K+ Views

To format and return the string representation of a Period object in Pandas, use the strftime() method. This method accepts format specifiers to customize the output format, such as '%d-%b-%Y' for day-month-year representation. What is a Period Object? A Pandas Period represents a specific time span with a defined frequency. It can represent anything from seconds to years, depending on the frequency parameter specified. Creating a Period Object First, let's create a Period object with second-level frequency ? import pandas as pd # Create a Period object with second frequency period = pd.Period(freq="S", ...

Read More

Python Pandas - Change the frequency of the given Period object from Seconds to Daily frequency

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 603 Views

To change the frequency of a Pandas Period object from seconds to daily frequency, use the period.asfreq() method with the parameter 'D'. This conversion aggregates time information to the day level. Understanding Period Objects A Pandas Period represents a specific time span with an associated frequency. When you convert from a higher frequency (seconds) to a lower frequency (daily), the result retains only the date component ? import pandas as pd # Create a Period object with seconds frequency period = pd.Period(freq="S", year=2021, month=4, day=16, hour=2, minute=35, second=15) print("Original Period (seconds frequency):") print(period) print("Frequency:", period.freq) ...

Read More

Python Pandas - Convert Period to desired frequency

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 655 Views

To convert Period to desired frequency, use the period.asfreq() method. This method allows you to change the frequency of a Pandas Period object to match your analysis requirements. What is asfreq()? The asfreq() method converts a Period from one frequency to another. When converting to a higher frequency (like daily to hourly), it uses specific rules to determine the exact timestamp within the period. 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:15:40") period2 = ...

Read More

Python Pandas - Get the year from the Period object

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 601 Views

To get the year from the Period object, use the period.year property. A pandas Period represents a specific span of time with a given frequency. Importing Required Library First, import pandas to work with Period objects ? import pandas as pd Creating Period Objects You can create Period objects using different approaches ? import pandas as pd # Create Period from date string period1 = pd.Period("2020-09-23") # Create Period with specific frequency and date components period2 = pd.Period(freq="D", year=2021, month=4, day=16, hour=2, minute=35) print("Period1:", period1) print("Period2:", period2) ...

Read More

Python Pandas - Get the week of the year on the given Period

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 286 Views

To get the week of the year on the given Period, use the period.weekofyear property. This property returns the week number (1-53) for any given date within a Period object. Syntax period.weekofyear Where period is a pandas Period object representing a specific date or time period. Creating Period Objects First, import the required library and create Period objects using different methods − import pandas as pd # Creating Period objects using different approaches period1 = pd.Period("2020-09-23") period2 = pd.Period(freq="D", year=2021, month=4, day=16, hour=2, minute=35) # Display the Period objects ...

Read More

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

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 379 Views

To find the start time for a given Period object, use the start_time property. A Pandas Period represents a specific time span, and start_time returns the exact timestamp when that period begins. What is start_time Property? The start_time property returns a Timestamp object representing the start of the period. This is useful when you need the precise beginning moment of a time period ? import pandas as pd # Create a Period object period = pd.Period("2020-09-22") print("Period:", period) print("Start time:", period.start_time) print("Type:", type(period.start_time)) Period: 2020-09-22 Start time: 2020-09-22 00:00:00 Type: ...

Read More

Program to find out the largest sum value of a BST in a given binary tree in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 265 Views

Suppose we are provided a binary tree. We have to find out if there exist binary search trees (BST) in the subtrees of it and find out the sum of the largest BST. To find out the sum, we add the values of each node in that BST. We return the sum value as output. So, if the input is like ? then the output will be 12. The BST in the given binary tree is ? sum of the nodes = 12. Algorithm To solve this, we will follow ...

Read More

Program to find out if a BST is present in a given binary tree in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 228 Views

A Binary Search Tree (BST) is a special type of binary tree where the left subtree contains values less than or equal to the root, and the right subtree contains values greater than or equal to the root. This problem asks us to find the largest BST subtree within a given binary tree. Original Tree: 1 4 6 ...

Read More

Program to find out the k-th largest product of elements of two arrays in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 293 Views

Given two lists containing integer numbers, we need to find the k-th largest product by multiplying each element from the first list with each element from the second list. This problem can be efficiently solved using a min-heap to track the k largest products. So, if the input is like p = [2, 5], q = [6, 8], k = 2, then the output will be 16. The multiplication results are: 2 × 6 = 12, 2 × 8 = 16, 5 × 6 = 30, 5 × 8 = 40. When sorted in descending order: [40, 30, ...

Read More
Showing 2741–2750 of 61,297 articles
« Prev 1 273 274 275 276 277 6130 Next »
Advertisements