Articles on Trending Technologies

Technical articles with clear explanations and examples

Python Pandas - Extract the microseconds from the DateTimeIndex with specific time series frequency

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 245 Views

To extract the microseconds from a DateTimeIndex with specific time series frequency, use the DateTimeIndex.microsecond property. This property returns an Index containing the microsecond component of each datetime. Creating DateTimeIndex with Microsecond Frequency First, let's create a DateTimeIndex with microsecond frequency ? import pandas as pd # Create DatetimeIndex with period 6 and frequency as 'us' (microseconds) # The timezone is Australia/Sydney datetimeindex = pd.date_range('2021-10-20 02:30:50', periods=6, tz='Australia/Sydney', freq='us') print("DateTimeIndex...") print(datetimeindex) DateTimeIndex... DatetimeIndex(['2021-10-20 02:30:50+11:00', '2021-10-20 02:30:50.000001+11:00', ...

Read More

Python Pandas - Extract the seconds from the DateTimeIndex with specific time series frequency

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 576 Views

To extract the seconds from the DateTimeIndex with specific time series frequency, use the DateTimeIndex.second property. This property returns an Int64Index containing the second component of each datetime in the index. Syntax DateTimeIndex.second Creating a DateTimeIndex First, let's create a DateTimeIndex with a seconds frequency to demonstrate the extraction ? import pandas as pd # Create DatetimeIndex with period 6 and frequency as S (seconds) # The timezone is Australia/Sydney datetimeindex = pd.date_range('2021-10-20 02:30:50', periods=6, tz='Australia/Sydney', freq='S') # Display DateTimeIndex print("DateTimeIndex...", datetimeindex) DateTimeIndex... DatetimeIndex(['2021-10-20 02:30:50+11:00', '2021-10-20 02:30:51+11:00', ...

Read More

Python Pandas - Extract the minute from DateTimeIndex with specific time series frequency

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

To extract the minute from the DateTimeIndex with specific time series frequency, use the DateTimeIndex.minute property. This property returns an Int64Index containing the minute values for each timestamp in the DateTimeIndex. Syntax DateTimeIndex.minute Creating a DateTimeIndex First, let's create a DateTimeIndex with a specific frequency. We'll use period 6 and frequency as 'T' (minute) with Australia/Sydney timezone − import pandas as pd # Create DatetimeIndex with period 6 and frequency as T i.e. minute # The timezone is Australia/Sydney datetimeindex = pd.date_range('2021-10-20 02:30:55', periods=6, tz='Australia/Sydney', freq='T') # Display DateTimeIndex print("DateTimeIndex...") ...

Read More

Program to count number of operations needed to make string as concatenation of same string twice in Python

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

Suppose we have a lowercase string s. We need to find the minimum number of operations (delete, insert, or update) required to make s equal to the concatenation of some string t with itself (s = t + t). So, if the input is like s = "pqrxqsr", then the output will be 2. We can update the "x" with "p" and delete "s", making s = "pqrpqr", which is t + t where t = "pqr". Algorithm We solve this by trying all possible split points and using edit distance ? For each position ...

Read More

Program to find length of smallest sublist that can be deleted to make sum divisible by k in Python

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

When working with arrays and modular arithmetic, sometimes we need to find the shortest subarray to remove so that the remaining elements' sum is divisible by a given number k. This problem uses prefix sums and hash maps to efficiently find the optimal subarray to delete. Problem Understanding Given a list of positive integers and a positive number k, we need to find the length of the shortest subarray that can be deleted to make the remaining sum divisible by k. We cannot delete the entire array. Example For nums = [5, 8, 6, 3] and ...

Read More

Program to find minimum deletions to make strings strings in Python

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

Sometimes we need to find the minimum number of deletions required to make two strings equal. This is a classic dynamic programming problem that can be solved by finding the Longest Common Subsequence (LCS) and subtracting it from the total length of both strings. Given two lowercase strings s and t, we need to delete characters from either string to make them identical. The key insight is that we want to keep the maximum number of common characters and delete the rest. Problem Example If we have s = "pipe" and t = "ripe", we can delete ...

Read More

Program to find maximum profit after cutting rods and selling same length rods in Python

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

Suppose we have a list of rod lengths called rodLen. We also have two integers called profit and cost, representing profit per length and cost per cut. We can gain profit per unit length of a rod but we can only sell rods that are all of the same length. We can also cut a rod into two pieces such that their lengths are integers, but we have to pay cost amount for each cut. We can cut a rod as many times as we want. We have to find the maximum profit that we can make. So, if ...

Read More

Program to find maximum length of k ribbons of same length in Python

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

Suppose we have a list of positive numbers representing ribbon lengths and a value k. We can cut the ribbons as many times as we want, and we need to find the largest length r such that we can have k ribbons of length r. If no such solution exists, return -1. So, if the input is like ribbons = [1, 2, 5, 7, 15] and k = 5, then the output will be 5. We can cut the ribbon of size 15 into 3 pieces of length 5 each, cut the ribbon of size 7 into pieces of ...

Read More

Program to count substrings with all 1s in binary string in Python

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

Suppose we have a binary string s. We have to find the number of substrings that contain only "1"s. If the answer is too large, mod the result by 10^9+7. So, if the input is like s = "100111", then the output will be 7, because the substrings containing only "1"s are ["1", "1", "1", "1", "11", "11" and "111"]. Algorithm To solve this, we will follow these steps − Initialize a counter a to 0 for tracking consecutive 1s Initialize count to 0 for total substrings ...

Read More

Program to count number of square submatrices in given binary matrix in Python

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

A square submatrix is a subset of elements from a matrix arranged in a square pattern. In a binary matrix, we want to count square submatrices where all elements are 1. This problem uses dynamic programming to efficiently count all possible squares. Problem Understanding Given a binary matrix, we need to find the total number of square submatrices containing only 1s. For example: 0 1 1 0 1 1 This matrix has 5 square submatrices: one (2×2) square and four (1×1) squares. Algorithm Approach We use dynamic programming ...

Read More
Showing 2861–2870 of 61,297 articles
« Prev 1 285 286 287 288 289 6130 Next »
Advertisements