Articles on Trending Technologies

Technical articles with clear explanations and examples

Program to find out the minimum value from sum of node values of sub-trees in Python

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

Suppose we have a tree with nodes numbered 1 to n, where each node contains an integer value. When we remove any edge from the tree, it splits into two sub-trees. Our goal is to find the minimum possible difference between the sums of node values in these two sub-trees. The tree is given as a collection of edges, and the node values are provided in a list. Problem Understanding If the input is n = 6, edge_list = [[1, 2], [1, 3], [2, 4], [3, 5], [3, 6]], values = [15, 25, 15, 55, 15, 65], ...

Read More

Python Pandas CustomBusinessHour - Check if the given timestamp is on offset or not

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 321 Views

To check if a given timestamp is on offset or not, use the CustomBusinessHour.is_on_offset() method in Pandas. This method returns True if the timestamp falls within the custom business hours, and False otherwise. What is CustomBusinessHour? CustomBusinessHour is a DateOffset subclass that allows you to define custom business hours with specific start and end times. The is_on_offset() method checks whether a given timestamp falls within these defined business hours. Syntax CustomBusinessHour.is_on_offset(timestamp) Example Let's create a CustomBusinessHour offset and check if different timestamps are within the business hours ? import pandas ...

Read More

Python Pandas - Check if the given CustomBusinessHour is Anchored

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 148 Views

To check if a given CustomBusinessHour is anchored, use the is_anchored() method in Pandas. An anchored offset is tied to a specific point in time, like the beginning of a month or day. What is CustomBusinessHour? CustomBusinessHour is a DateOffset subclass that allows you to define custom business hours with specific start and end times ? import pandas as pd # Create a CustomBusinessHour offset with business hours 9:30 AM to 6:30 PM cbh_offset = pd.tseries.offsets.CustomBusinessHour(start="09:30", end="18:30") print("CustomBusinessHour Offset:", cbh_offset) CustomBusinessHour Offset: Checking if CustomBusinessHour is Anchored The ...

Read More

Python Pandas CustomBusinessHour - Roll provided date forward to next offset only if not on offset

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 259 Views

The rollforward() method in Pandas CustomBusinessHour moves a date forward to the next valid business hour only if the date is not already on a valid offset. If the date is already aligned with the custom business hour schedule, it remains unchanged. Understanding CustomBusinessHour CustomBusinessHour allows you to define custom business days and hours. It's useful when your business operates on non-standard schedules ? import pandas as pd # Create a CustomBusinessHour offset # n=5 means 5 business hours, weekmask defines valid days cbh_offset = pd.tseries.offsets.CustomBusinessHour(n=5, weekmask='Mon Tue Wed Fri') print("CustomBusinessHour Offset:") print(cbh_offset) ...

Read More

Python Pandas - Create a CustomBusinessHour Offset object

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 200 Views

To create a CustomBusinessHour object, use the pandas.tseries.offsets.CustomBusinessHour() method in Pandas. This offset allows you to define custom business hours with specific weekdays and time ranges. Syntax pandas.tseries.offsets.CustomBusinessHour(n=1, normalize=False, start='09:00', end='17:00', weekmask='Mon Tue Wed Thu Fri', calendar=None, offset=timedelta(0)) Parameters n − Number of business hours to offset (default: 1) weekmask − Valid business days as a string (default: 'Mon Tue Wed Thu Fri') start − Start time of business hours (default: '09:00') end − End time of business hours (default: '17:00') Basic Example Let's create a CustomBusinessHour offset with custom ...

Read More

Python Pandas - Get the weekmask applied on the CustomBusinessDay offset

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 258 Views

The weekmask property in Pandas allows you to retrieve the custom business days pattern applied to a CustomBusinessDay offset. This is useful for understanding which days of the week are considered valid business days in your custom offset. What is CustomBusinessDay? CustomBusinessDay is a DateOffset subclass that represents custom business days while excluding holidays. Unlike standard business days (Mon-Fri), you can specify your own pattern of valid business days using a weekmask. Creating a CustomBusinessDay with Weekmask First, let's create a timestamp and a CustomBusinessDay offset with a custom weekmask − import pandas as ...

Read More

Python Pandas - Create a CustomBusinessDay Offset object

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 500 Views

The CustomBusinessDay offset in Pandas allows you to create custom business day schedules by specifying which days of the week are valid business days. This is useful when you need to exclude specific weekdays or create non-standard business calendars. Syntax pd.tseries.offsets.CustomBusinessDay(n=1, weekmask='Mon Tue Wed Thu Fri', holidays=None) Parameters The main parameters for CustomBusinessDay are: n − Number of business days to offset (default: 1) weekmask − String specifying valid business days (default: 'Mon Tue Wed Thu Fri') holidays − List of dates to exclude as holidays (default: None) Creating a ...

Read More

Python Pandas BusinessHour offset object - Move to the next business day

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 349 Views

The BusinessHour offset in Pandas provides the next_bday property to move timestamps to the next business day. This is useful for financial calculations and business logic where weekends need to be skipped. Understanding BusinessHour Offset The BusinessHour is a DateOffset subclass that handles business day calculations. It automatically skips weekends and can include custom time offsets ? import datetime import pandas as pd # Create a BusinessHour offset with custom offset bhOffset = pd.tseries.offsets.BusinessHour(offset=datetime.timedelta(days=3, hours=3)) print("BusinessHour Offset:", bhOffset) BusinessHour Offset: Moving to Next Business Day Use the next_bday ...

Read More

Python Pandas - Display the end time of the custom business hour in 24h format from the BusinessHour offset object

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 147 Views

To display the end time of the custom business hour in 24h format from the BusinessHour offset object, use the BusinessHour.end property. This property returns the end time of your custom business hours as a tuple containing datetime.time objects. Syntax The basic syntax for creating a BusinessHour offset with custom hours ? bhOffset = pd.tseries.offsets.BusinessHour(start="HH:MM", end="HH:MM", n=hours) # Access end time using bhOffset.end Parameters start − Start time of business hours in 24h format (e.g., "09:30") end − End time of business hours in 24h format (e.g., "18:00") n − Number of ...

Read More

Python Pandas - Display the start time of the custom business hour in 24h format from the BusinessHour offset object

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 190 Views

To display the start time of the custom business hour in 24h format from the BusinessHour offset object, use the BusinessHour.start property. This property returns a tuple containing the start time as a datetime.time object. Creating a BusinessHour Offset First, let's create a BusinessHour offset with custom start and end times − import pandas as pd # Set the timestamp object in Pandas timestamp = pd.Timestamp('2021-9-30 06:50:20') # Display the Timestamp print("Timestamp...", timestamp) # Create the BusinessHour Offset # "start" is the start time of your custom business hour in 24h format # ...

Read More
Showing 1–10 of 61,303 articles
« Prev 1 2 3 4 5 6131 Next »
Advertisements