Programming Articles

Page 245 of 2547

Python Pandas - Return a dataframe of the components of the TimedeltaIndex

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 197 Views

The TimedeltaIndex.components property in Pandas returns a DataFrame containing the individual components (days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds) of each timedelta in the index. Creating a TimedeltaIndex First, let's create a TimedeltaIndex with various time durations ? import pandas as pd # Create a TimedeltaIndex with different time formats tdIndex = pd.TimedeltaIndex(data=['10 day 5h 2 min 35s 3us 10ns', '+22:39:19.999999', ...

Read More

Python Pandas - Extract the Number of nanoseconds for each element from TimeDeltaIndex

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 167 Views

To extract the number of nanoseconds for each element from a TimeDeltaIndex object, use the TimedeltaIndex.nanoseconds property. This property returns only the nanosecond component (0-999) from each timedelta, not the total nanoseconds. Syntax TimedeltaIndex.nanoseconds Creating a TimeDeltaIndex First, let's create a TimeDeltaIndex with various time components including nanoseconds ? import pandas as pd # Create a TimeDeltaIndex object with timedelta-like data tdIndex = pd.TimedeltaIndex(data=['10 day 5h 2 min 35s 3us 10ns', '+22:39:19.999999', ...

Read More

Python Pandas - Extract the Number of microseconds for each element from TimeDeltaIndex

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 161 Views

To extract the number of microseconds for each element from TimeDeltaIndex object, use the TimedeltaIndex.microseconds property. This property returns an Int64Index containing the microsecond component of each timedelta. Creating a TimeDeltaIndex First, let's create a TimeDeltaIndex object with various timedelta formats ? import pandas as pd # Create a TimeDeltaIndex object with different timedelta formats tdIndex = pd.TimedeltaIndex(data=['10 day 5h 2 min 35s 3us 10ns', '+22:39:19.999999', ...

Read More

Python Pandas - Extract the Number of seconds for each element from TimeDeltaIndex

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 224 Views

To extract the number of seconds for each element from TimeDeltaIndex object, use the TimedeltaIndex.seconds property. This property returns the seconds component (0-59) of each timedelta element. Creating a TimeDeltaIndex First, let's create a TimeDeltaIndex with various time intervals ? import pandas as pd # Create a TimeDeltaIndex object with different time intervals tdIndex = pd.TimedeltaIndex(data=['10 day 5h 2 min 35s 3us 10ns', '+22:39:19.999999', ...

Read More

Program to find length of longest repeating substring in a string in Python

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

A repeating substring is a substring that occurs at least twice in a string. In this tutorial, we'll find the length of the longest repeating substring using Python's suffix array approach. So, if the input is like s = "abdgoalputabdtypeabd", then the output will be 3, because the longest substring that occurs more than once is "abd". Algorithm Overview To solve this problem, we will follow these steps − Generate all suffixes of the string Sort the suffixes lexicographically Find the longest common prefix between adjacent suffixes Return the maximum length found Helper ...

Read More

Program to find length longest prefix sequence of a word array in Python

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

Suppose we have a list of words called w, with lowercase strings. We have to find the length of the longest sequence of w where each previous word is the prefix of the next word and the next word has just one new character appended. So, if the input is like w = ["pqr", "pq", "m", "mn", "pqrs"], then the output will be 3 because we can get the sequence: ["pq", "pqr", "pqrs"], whose length is 3. Algorithm To solve this, we will follow these steps − Sort the list w ...

Read More

Program to find length of longest consecutively increasing substring in Python

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

Given a lowercase string containing English letters and "?" symbols, we need to find the length of the longest consecutively increasing substring that starts with letter "a". For each "?" we can either remove it or replace it with any lowercase letter. For example, if the input is s = "vta???defke", we can transform it into "vtabcdefke" where "abcdef" is the longest consecutively increasing substring starting with "a", giving us a length of 6. Algorithm We'll use a greedy approach to track the current sequence length and question marks ? maxlen − Maximum length found ...

Read More

Program to find length of longest consecutive sublist with unique elements in Python

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

Suppose we have a list of numbers called nums, where all elements are unique. We have to find the length of the longest sublist that contains consecutive elements. So, if the input is like nums = [3, 6, 7, 5, 4, 9], then the output will be 5, because the sublist [3, 6, 7, 5, 4] contains all consecutive elements from 3 to 7. Algorithm Approach To solve this, we will follow these steps − Initialize ret := 0 to store the maximum length For each starting ...

Read More

Program to find longest consecutive run of 1s in binary form of n in Python

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

Suppose we have a non-negative value n, we have to find the length of the longest consecutive run of 1s in its binary representation. So, if the input is like n = 1469, then the output will be 4, because binary representation of 1469 is "10110111101", so there are four consecutive 1s. Approach To solve this, we will follow these steps ? count := 0 while n is not same as 0, do n := n AND (n after shifting one bit to the left) count := count + 1 return count How It Works The algorithm uses bit manipulation where n & (n

Read More

Program to find length of longest substring with 1s in a binary string after one 0-flip in Python

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

Suppose we have a binary string s. We are allowed to flip at most one "0" to "1", we have to find the length of the longest contiguous substring of 1s. So, if the input is like s = "1010110001", then the output will be 4, as if we flip the zero present at index 3, then we get the string "1011110001", here length of the longest substring of 1s is 4. Algorithm To solve this, we will follow these steps ? n := size of s ans := ...

Read More
Showing 2441–2450 of 25,466 articles
« Prev 1 243 244 245 246 247 2547 Next »
Advertisements