AmitDiwan

AmitDiwan

8,392 Articles Published

Articles by AmitDiwan

Page 46 of 840

Return the length of a string array element-wise in Python

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

To return the length of a string array element-wise, use the numpy.char.str_len() method in Python NumPy. The method returns an output array of integers representing the length of each string element. Syntax numpy.char.str_len(a) Parameters: a − Array-like of str or unicode Returns: Array of integers representing the length of each string element. Basic Example Let's create a simple string array and find the length of each element ? import numpy as np # Create array of strings names = np.array(['Amy', 'Scarlett', 'Katie', 'Brad', 'Tom']) # Get ...

Read More

Test whether similar int type of different sizes are subdtypes of integer class in Python

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 133 Views

To test whether similar int type of different sizes are subdtypes of integer class, use the numpy.issubdtype() method in Python NumPy. The parameters are the dtype or object coercible to one. Syntax numpy.issubdtype(arg1, arg2) Parameters: arg1: dtype or object coercible to one arg2: dtype or object coercible to one Returns: Boolean value indicating whether arg1 is a subtype of arg2. Testing Signed Integer Subtypes First, let's check if different sized integer types are subtypes of np.signedinteger − import numpy as np # Testing different signed integer sizes ...

Read More

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

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 325 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 153 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 268 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 210 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 271 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 507 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 358 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 159 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
Showing 451–460 of 8,392 articles
« Prev 1 44 45 46 47 48 840 Next »
Advertisements