Programming Articles

Page 253 of 2547

Python Pandas - Return index locations of values between particular time of day in DateTimeIndex

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 300 Views

To return index locations of values between particular time of day in DateTimeIndex, use the DateTimeIndex.indexer_between_time() method. This method is useful for filtering time-series data based on specific time ranges. Syntax DateTimeIndex.indexer_between_time(start_time, end_time, include_start=True, include_end=True) Parameters The method accepts the following parameters: start_time − The start time in 'HH:MM:SS' format end_time − The end time in 'HH:MM:SS' format include_start − Boolean to include start time (default: True) include_end − Boolean to include end time (default: True) Creating a DateTimeIndex First, let's create a DateTimeIndex with timezone information − ...

Read More

Python Pandas - Return index locations of values at particular time of day in DateTimeIndex

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 658 Views

To return index locations of values at particular time of day in DateTimeIndex, use the DateTimeIndex.indexer_at_time() method. This method returns an array of integer positions where the time component matches the specified time. Syntax DateTimeIndex.indexer_at_time(time, asof=False) Parameters The key parameters are ? time ? Time as a time object or string asof ? Return the latest index location if exact time not found (default: False) Creating DateTimeIndex First, let's create a DateTimeIndex with timezone-aware timestamps ? import pandas as pd # Create DatetimeIndex with 20-minute intervals ...

Read More

Program to check every sublist in a list containing at least one unique element in Python

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

Suppose we have a list of elements called nums, we have to check whether every sublist has at least 1 element in it that occurs exactly once in the sublist or not. We have to solve this problem in linear time. So, if the input is like nums = [5, 10, 20, 10, 0], then the output will be True, because every sublist in nums has at least one element which has occurred only once. [[5], [10], [20], [10], [0], [5, 10], [10, 20], [20, 10], [10, 0], [5, 10, 20], [10, 20, 10], [20, 10, 0], [5, 10, ...

Read More

Python Pandas - Detect the frequency of the given DatetimeIndex object

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 250 Views

To detect the frequency of a given DatetimeIndex object, use the DatetimeIndex.inferred_freq property. This property automatically infers the frequency pattern from the datetime values. Creating a DatetimeIndex First, let's create a DatetimeIndex with a specific frequency ? import pandas as pd # Create DatetimeIndex with 5 periods and 3-year frequency # Using Australia/Adelaide timezone datetimeindex = pd.date_range('2021-10-30 02:30:50', periods=5, tz='Australia/Adelaide', freq='3Y') print("DateTimeIndex...") print(datetimeindex) DateTimeIndex... DatetimeIndex(['2021-12-31 02:30:50+10:30', '2024-12-31 02:30:50+10:30', '2027-12-31 02:30:50+10:30', '2030-12-31 02:30:50+10:30', ...

Read More

Minimum number of moves to escape maze matrix in Python

Arnab Chakraborty
Arnab Chakraborty
Updated on 26-Mar-2026 1K+ Views

Suppose we have a binary matrix, where 0 represents an empty cell, and 1 is a wall. Starting from the top left corner (0, 0), we need to find the minimum number of cells to reach the bottom right corner (R-1, C-1), where R is the number of rows and C is the number of columns. If no path exists, return -1. This is a classic shortest path problem that can be solved using Breadth-First Search (BFS). Problem Example If the input matrix is like ? 00010 00110 00011 11000 Then the output ...

Read More

Python Pandas - Indicate whether the date in DateTimeIndex is the last day of the year

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 186 Views

To check whether dates in a DateTimeIndex fall on the last day of the year (December 31st), use the DateTimeIndex.is_year_end property. This returns a boolean array indicating which dates are year-end dates. Syntax DateTimeIndex.is_year_end Creating a DateTimeIndex First, let's create a DateTimeIndex with dates around year-end ? import pandas as pd # Create DateTimeIndex with period 6 and frequency as 2 days datetimeindex = pd.date_range('2021-12-25 02:30:50', periods=6, tz='Australia/Adelaide', freq='2D') print("DateTimeIndex...") print(datetimeindex) DateTimeIndex... DatetimeIndex(['2021-12-25 02:30:50+10:30', '2021-12-27 02:30:50+10:30', ...

Read More

Python Pandas - Indicate whether the date in DateTimeIndex is the first day of the year

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 200 Views

To check whether the date in DateTimeIndex is the first day of the year, use the DateTimeIndex.is_year_start property. This property returns a boolean array indicating which dates are January 1st. Syntax DateTimeIndex.is_year_start Creating a DateTimeIndex First, let's create a DateTimeIndex that spans across a year boundary to demonstrate the property ? import pandas as pd # Create DateTimeIndex spanning year boundary datetimeindex = pd.date_range('2021-12-30 02:30:50', periods=6, tz='Australia/Adelaide', freq='1D') print("DateTimeIndex...") print(datetimeindex) DateTimeIndex... DatetimeIndex(['2021-12-30 02:30:50+10:30', '2021-12-31 02:30:50+10:30', ...

Read More

Program to find number of quadruples for which product of first and last pairs are same in Python

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

Suppose we have a list of numbers called nums, with unique positive numbers. We have to find the number of quadruples like (a, b, c, d) from nums such that a*b = c*d, where a, b, c and d are all distinct elements of nums. So, if the input is like nums = [3, 6, 4, 8], then the output will be 8, because the quadruples are [[3, 8, 6, 4], [3, 8, 4, 6], [8, 3, 6, 4], [8, 3, 4, 6], [6, 4, 3, 8], [4, 6, 3, 8], [6, 4, 8, 3], [4, 6, 8, 3]]. ...

Read More

Python Pandas - Indicate whether the date in DateTimeIndex is the last day of the quarter

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 318 Views

To check whether the date in DateTimeIndex is the last day of the quarter, use the DateTimeIndex.is_quarter_end property. This property returns a boolean array indicating which dates fall on the last day of their respective quarters. Understanding Quarter Divisions Before using is_quarter_end, it's important to understand how pandas divides the year into quarters ? Quarter 1: January 1st to March 31st Quarter 2: April 1st to June 30th Quarter 3: July 1st to September 30th Quarter 4: October 1st to December 31st Basic Example Let's create a DateTimeIndex and check which dates are ...

Read More

Python Pandas - Indicate whether the date in DateTimeIndex is the first day of the quarter

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 186 Views

To check whether the date in DateTimeIndex is the first day of the quarter, use the DateTimeIndex.is_quarter_start property. This property returns a boolean array indicating which dates fall on the first day of their respective quarters. Understanding Quarters In Pandas, a year is divided into four quarters ? Quarter 1: January 1 to March 31 Quarter 2: April 1 to June 30 Quarter 3: July 1 to September 30 Quarter 4: October 1 to December 31 Syntax DateTimeIndex.is_quarter_start Example Let's create a DateTimeIndex and check which dates are the ...

Read More
Showing 2521–2530 of 25,466 articles
« Prev 1 251 252 253 254 255 2547 Next »
Advertisements