Programming Articles

Page 254 of 2547

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

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 188 Views

To check whether dates in a DateTimeIndex correspond to the last day of their respective months, use the is_month_end property. This returns a boolean array indicating which dates fall on month-end dates. Syntax DateTimeIndex.is_month_end Creating a DateTimeIndex First, let's create a DateTimeIndex with various dates ? import pandas as pd # Create DateTimeIndex with 15-day intervals datetimeindex = pd.date_range('2021-9-15 06:40:35', periods=6, tz='Australia/Adelaide', freq='15D') print("DateTimeIndex...") print(datetimeindex) DateTimeIndex... DatetimeIndex(['2021-09-15 06:40:35+09:30', '2021-09-30 06:40:35+09:30', '2021-10-15 06:40:35+10:30', ...

Read More

Program to find number of operations needed to make pairs from first and last side are with same sum in Python

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

Suppose we have a list of numbers called nums with even length. We can perform operations where we select any number and update it with a value in range [1, maximum of nums]. We need to find the minimum number of operations required so that for every index i, nums[i] + nums[n-1-i] equals the same number. For example, if nums = [8, 6, 2, 5, 9, 2], we can change the first 2 at index 2 to 5, and 9 at index 4 to 4. The array becomes [8, 6, 5, 5, 4, 2], where all pairs sum to ...

Read More

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

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 161 Views

To check whether the date in DateTimeIndex is the first day of the month, use the DateTimeIndex.is_month_start property. This boolean property returns True for dates that fall on the first day of their respective months. Syntax DateTimeIndex.is_month_start Creating a DateTimeIndex First, let's create a DateTimeIndex with various dates to demonstrate the functionality − import pandas as pd # Create a DateTimeIndex with period 6 and frequency as 5 days # The timezone is Australia/Adelaide datetimeindex = pd.date_range('2021-9-21 02:30:50', periods=6, tz='Australia/Adelaide', freq='5D') # Display DateTimeIndex print("DateTimeIndex...") print(datetimeindex) DateTimeIndex... ...

Read More

Program to find number of elements can be removed to make odd and even indexed elements sum equal in Python

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

Given a list of numbers, we need to find how many elements can be removed such that the sum of even-indexed elements equals the sum of odd-indexed elements in the resulting array. This problem uses prefix sums to efficiently calculate sums after element removal. Problem Understanding For each element at index i, we simulate its removal and check if the remaining elements have equal even and odd index sums. After removing an element, all subsequent elements shift left by one position, changing their index parity. Example Given nums = [6, 8, 5, 2, 3] ? ...

Read More

Python Pandas - Extract the frequency object as a string from the DateTimeIndex

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 296 Views

To extract the frequency object as a string from the DateTimeIndex, use the DateTimeIndex.freqstr property in Pandas. This property returns the frequency as a string representation, which is useful for displaying or storing the frequency information. Creating a DateTimeIndex with Frequency First, let's create a DateTimeIndex with a specific frequency ? import pandas as pd # Create DatetimeIndex with period 6 and frequency as D (daily) # The timezone is Australia/Adelaide datetimeindex = pd.date_range('2021-10-20 02:30:50', periods=6, tz='Australia/Adelaide', freq='D') print("DateTimeIndex...") print(datetimeindex) DateTimeIndex... DatetimeIndex(['2021-10-20 02:30:50+10:30', '2021-10-21 02:30:50+10:30', ...

Read More

Python Pandas - Extract the frequency from the DateTimeIndex

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

To extract the frequency from the DateTimeIndex, use the DateTimeIndex.freq property in Pandas. This property returns the frequency object associated with the DateTimeIndex, which is useful for understanding the time intervals between consecutive dates. Syntax DateTimeIndex.freq Creating a DateTimeIndex with Frequency First, let's create a DateTimeIndex with a specific frequency to demonstrate the extraction ? import pandas as pd # Create DateTimeIndex with period 6 and frequency as D (day) # The timezone is Australia/Adelaide datetimeindex = pd.date_range('2021-10-20 02:30:50', periods=6, tz='Australia/Adelaide', freq='D') # Display DateTimeIndex print("DateTimeIndex...") print(datetimeindex) ...

Read More

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

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

To extract the timezone from a DateTimeIndex with specific time series frequency, use the DateTimeIndex.tz property. This is useful when working with time series data across different geographical regions. Syntax The basic syntax to extract timezone information ? DateTimeIndex.tz Creating DateTimeIndex with Timezone First, let's create a DateTimeIndex with timezone information and specific frequency ? import pandas as pd # Create DatetimeIndex with period 6 and frequency as D (daily) # The timezone is Australia/Sydney datetimeindex = pd.date_range('2021-10-20 02:30:50', periods=6, tz='Australia/Sydney', freq='D') # Display DateTimeIndex print("DateTimeIndex...") print(datetimeindex) ...

Read More

Python Pandas - Extract the quarter of the date from the DateTimeIndex with specific time series frequency

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

To extract the quarter of the date from the DateTimeIndex with specific time series frequency, use the DateTimeIndex.quarter property. Syntax DateTimeIndex.quarter This property returns an Int64Index containing the quarter of each date in the DateTimeIndex. Quarter Mapping The quarters are mapped as follows ? Quarter 1 = January to March Quarter 2 = April to June Quarter 3 = July to September Quarter 4 = October to December Creating a DateTimeIndex First, let's create a DateTimeIndex with specific frequency ? import pandas as pd # ...

Read More

Program to find stone removal rate in K hours in Python

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

Suppose we have a list of numbers called piles and a value k. The piles[i] represents the number of stones on pile i. On each hour, we select any pile and remove r number of stones from that pile. If we pick a pile with fewer than r stones, it still takes an hour to clear the pile. We have to find the minimum value of r, such that we can remove all the stones in less than or equal to k hours. So, if the input is like piles = [3, 6, 4] and k = 5, then ...

Read More

Python Pandas - Extract the day of week from the DateTimeIndex with specific time series frequency

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 337 Views

To extract the day of week from a DateTimeIndex with specific time series frequency, use the DateTimeIndex.dayofweek property. This property returns integers from 0-6 representing Monday through Sunday. Creating a DateTimeIndex with Frequency First, let's create a DateTimeIndex with a specific frequency using pd.date_range() ? import pandas as pd # Create DatetimeIndex with period 6 and frequency 3D (every 3 days) datetimeindex = pd.date_range('2021-10-20 02:30:50', periods=6, tz='Australia/Sydney', freq='3D') print("DateTimeIndex...") print(datetimeindex) DateTimeIndex... DatetimeIndex(['2021-10-20 02:30:50+11:00', '2021-10-23 02:30:50+11:00', '2021-10-26 ...

Read More
Showing 2531–2540 of 25,466 articles
« Prev 1 252 253 254 255 256 2547 Next »
Advertisements