Server Side Programming Articles

Page 240 of 2109

Python Pandas - Change the frequency of the given Period object from Seconds to Daily frequency

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 603 Views

To change the frequency of a Pandas Period object from seconds to daily frequency, use the period.asfreq() method with the parameter 'D'. This conversion aggregates time information to the day level. Understanding Period Objects A Pandas Period represents a specific time span with an associated frequency. When you convert from a higher frequency (seconds) to a lower frequency (daily), the result retains only the date component ? import pandas as pd # Create a Period object with seconds frequency period = pd.Period(freq="S", year=2021, month=4, day=16, hour=2, minute=35, second=15) print("Original Period (seconds frequency):") print(period) print("Frequency:", period.freq) ...

Read More

Python Pandas - Convert Period to desired frequency

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 655 Views

To convert Period to desired frequency, use the period.asfreq() method. This method allows you to change the frequency of a Pandas Period object to match your analysis requirements. What is asfreq()? The asfreq() method converts a Period from one frequency to another. When converting to a higher frequency (like daily to hourly), it uses specific rules to determine the exact timestamp within the period. Creating Period Objects First, let's create Period objects with different frequencies − import pandas as pd # Create Period objects with different frequencies period1 = pd.Period("2020-09-23 03:15:40") period2 = ...

Read More

Python Pandas - Get the year from the Period object

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 601 Views

To get the year from the Period object, use the period.year property. A pandas Period represents a specific span of time with a given frequency. Importing Required Library First, import pandas to work with Period objects ? import pandas as pd Creating Period Objects You can create Period objects using different approaches ? import pandas as pd # Create Period from date string period1 = pd.Period("2020-09-23") # Create Period with specific frequency and date components period2 = pd.Period(freq="D", year=2021, month=4, day=16, hour=2, minute=35) print("Period1:", period1) print("Period2:", period2) ...

Read More

Python Pandas - Get the week of the year on the given Period

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 286 Views

To get the week of the year on the given Period, use the period.weekofyear property. This property returns the week number (1-53) for any given date within a Period object. Syntax period.weekofyear Where period is a pandas Period object representing a specific date or time period. Creating Period Objects First, import the required library and create Period objects using different methods − import pandas as pd # Creating Period objects using different approaches period1 = pd.Period("2020-09-23") period2 = pd.Period(freq="D", year=2021, month=4, day=16, hour=2, minute=35) # Display the Period objects ...

Read More

Python Pandas - Find the start time for the given Period object

AmitDiwan
AmitDiwan
Updated on 26-Mar-2026 379 Views

To find the start time for a given Period object, use the start_time property. A Pandas Period represents a specific time span, and start_time returns the exact timestamp when that period begins. What is start_time Property? The start_time property returns a Timestamp object representing the start of the period. This is useful when you need the precise beginning moment of a time period ? import pandas as pd # Create a Period object period = pd.Period("2020-09-22") print("Period:", period) print("Start time:", period.start_time) print("Type:", type(period.start_time)) Period: 2020-09-22 Start time: 2020-09-22 00:00:00 Type: ...

Read More

Program to find out the largest sum value of a BST in a given binary tree in Python

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

Suppose we are provided a binary tree. We have to find out if there exist binary search trees (BST) in the subtrees of it and find out the sum of the largest BST. To find out the sum, we add the values of each node in that BST. We return the sum value as output. So, if the input is like ? then the output will be 12. The BST in the given binary tree is ? sum of the nodes = 12. Algorithm To solve this, we will follow ...

Read More

Program to find out if a BST is present in a given binary tree in Python

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

A Binary Search Tree (BST) is a special type of binary tree where the left subtree contains values less than or equal to the root, and the right subtree contains values greater than or equal to the root. This problem asks us to find the largest BST subtree within a given binary tree. Original Tree: 1 4 6 ...

Read More

Program to find out the k-th largest product of elements of two arrays in Python

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

Given two lists containing integer numbers, we need to find the k-th largest product by multiplying each element from the first list with each element from the second list. This problem can be efficiently solved using a min-heap to track the k largest products. So, if the input is like p = [2, 5], q = [6, 8], k = 2, then the output will be 16. The multiplication results are: 2 × 6 = 12, 2 × 8 = 16, 5 × 6 = 30, 5 × 8 = 40. When sorted in descending order: [40, 30, ...

Read More

Program to find how many lines intersect in Python

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

Sometimes we need to find how many lines intersect within a given range. Given a list of lines in the form (m, c) representing y = mx + c, we can determine which lines intersect between x = l and x = h. So, if the input is like input_list = [[4, 6], [-6, 10], [8, 12]], l = 0, h = 2, then the output will be 2. ...

Read More

Program to find out the total number of characters to be changed to fix a misspelled word in Python

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

This problem involves finding the minimum number of character changes needed to correct misspelled city names in a tour route. Given a list of cities that a bus visits in order and a list of one-way roads connecting cities, we need to find valid paths and calculate the minimum corrections required. Problem Understanding The algorithm uses dynamic programming to find the optimal path through valid roads while minimizing character differences between the given city names and actual city names. Algorithm Steps The solution follows these key steps − Create a helper function to calculate ...

Read More
Showing 2391–2400 of 21,090 articles
« Prev 1 238 239 240 241 242 2109 Next »
Advertisements