Found 26504 Articles for Server Side Programming

Python Pandas - How to convert DateTimeIndex to Period

AmitDiwan
Updated on 19-Oct-2021 10:04:05

2K+ Views

To convert DateTimeIndex to Period, use the datetimeindex.to_period() method in Pandas. The frequency is set using the freq parameter.At first, import the required libraries −import pandas as pdCreate a DatetimeIndex with period 5 and frequency as Y i.e. year −datetimeindex = pd.date_range('2021-10-18 07:20:32.261811624', periods=5, freq='2Y') Display DateTimeIndex −print("DateTimeIndex...", datetimeindex)Convert DateTimeIndex to Period. We have set the frequency as Month using the "freq" parameter with value 'M' −print("Convert DateTimeIndex to Period...", datetimeindex.to_period(freq='M'))ExampleFollowing is the code −import pandas as pd # DatetimeIndex with period 5 and frequency as Y i.e. year # timezone is Australia/Adelaide datetimeindex = pd.date_range('2021-10-18 07:20:32.261811624', periods=5, freq='2Y') ... Read More

Program to find area of largest submatrix by column rearrangements in Python

Arnab Chakraborty
Updated on 19-Oct-2021 10:07:15

271 Views

Suppose we have a binary matrix. We can first rearrange the columns as many times as we want, then find return the area of the largest submatrix containing only 1s.So, if the input is like100111101then the output will be 4, because we can arrange is like −100111110To solve this, we will follow these steps −n := row count of matrixm := column count of matrixans := 0for i in range 1 to n - 1, dofor j in range 0 to m - 1, doif matrix[i, j] is 1, thenmatrix[i, j] := matrix[i, j] + matrix[i-1, j]for each row in ... Read More

Python Pandas - How to perform ceil operation on the DateTimeIndex with specified frequency

AmitDiwan
Updated on 19-Oct-2021 10:02:32

114 Views

To perform ceil operation on the DateTimeIndex with specified frequency, use the DateTimeIndex.ceil() method. For frequency, use the freq parameter.At first, import the required libraries −import pandas as pdCreate a DatetimeIndex with period 5 and frequency as S i.e. seconds. The timezone is Australia/Adelaide −datetimeindex = pd.date_range('2021-10-18 07:20:32.261811624', periods=5, tz='Australia/Adelaide', freq='40S')Display DateTimeIndex −print("DateTimeIndex...", datetimeindex) Ceil operation on DateTimeIndex date with specified frequency −print("Performing ceil operation...", datetimeindex.ceil(freq='us'))ExampleFollowing is the code −import pandas as pd # DatetimeIndex with period 5 and frequency as S i.e. seconds # timezone is Australia/Adelaide datetimeindex = pd.date_range('2021-10-18 07:20:32.261811624', periods=5, tz='Australia/Adelaide', freq='40S') # display DateTimeIndex ... Read More

Program to find largest kth index value of one list in Python

Arnab Chakraborty
Updated on 19-Oct-2021 10:03:28

203 Views

Suppose we have three values n, total, and k. Now consider a list of size n whose sum is same as total and where the absolute difference between any two consecutive elements is at most 1. We have to find the maximum value at index k of such a list.So, if the input is like n = 5 total = 15 k = 3, then the output will be 4, because one possible list is like [3, 2, 3, 4, 3], maximum element that is found at index 3 is 4.To solve this, we will follow these steps −x := ... Read More

Python Pandas - How to perform ceil operation on the DateTimeIndex with microseconds frequency

AmitDiwan
Updated on 19-Oct-2021 10:01:04

128 Views

To perform ceil operation on the DateTimeIndex with microseconds frequency, use the DateTimeIndex.ceil() method. For microseconds frequency, use the freq parameter with value ‘us’.At first, import the required libraries −import pandas as pdCreate a DatetimeIndex with period 5 and frequency as S i.e. seconds −datetimeindex = pd.date_range('2021-10-18 07:20:32.261811624', periods=5, tz='Australia/Adelaide', freq='40S')Display DateTimeIndex −print("DateTimeIndex...", datetimeindex) Perform Ceil operation on DateTimeIndex date with microseconds frequency. For microseconds frequency, we have used 'us' −print("Performing ceil operation with microseconds frequency...", datetimeindex.ceil(freq='us'))ExampleFollowing is the code −import pandas as pd # DatetimeIndex with period 5 and frequency as S i.e. seconds # timezone is Australia/Adelaide ... Read More

Python Pandas - How to perform ceil operation on the DateTimeIndex with milliseconds frequency

AmitDiwan
Updated on 19-Oct-2021 09:59:56

167 Views

To perform ceil operation on the DateTimeIndex with milliseconds frequency, use the DateTimeIndex.ceil() method. For milliseconds frequency, use the freq parameter with value ‘ms’.At first, import the required libraries −import pandas as pdCreate a DatetimeIndex with period 5 and frequency as S i.e. seconds. The timezone is Australia/Adelaide −datetimeindex = pd.date_range('2021-10-18 07:20:32.261811624', periods=5, tz='Australia/Adelaide', freq='40S')Ceil operation on DateTimeIndex date with milliseconds frequency. For milliseconds frequency, we have used 'ms' −print("Performing ceil operation with milliseconds frequency...", datetimeindex.ceil(freq='ms'))ExampleFollowing is the code −import pandas as pd # DatetimeIndex with period 5 and frequency as S i.e. seconds # timezone is Australia/Adelaide datetimeindex ... Read More

Program to find kth smallest element in linear time in Python

Arnab Chakraborty
Updated on 19-Oct-2021 10:01:16

2K+ Views

Suppose we have a list of numbers called nums, we also have another value k, we have to find the kth (starting from 0) smallest element in the list. We have to solve this problem in O(n) time on average.So, if the input is like nums = [6, 4, 9, 3, 1] k = 2, then the output will be 4, as after sorting the list will be like [1, 3, 4, 6, 9], the kth smallest element is 4.To solve this, we will follow these steps −maxHeap := a new empty heapfor i in range 0 to k, doinsert ... Read More

Python Pandas - How to perform ceil operation on the DateTimeIndex with seconds frequency

AmitDiwan
Updated on 19-Oct-2021 09:58:31

129 Views

To perform ceil operation on the DateTimeIndex with seconds frequency, use the DateTimeIndex.ceil() method. For seconds frequency, use the freq parameter with value ‘S’.At first, import the required libraries −import pandas as pdCreate a DatetimeIndex with period 5 and frequency as S i.e. seconds −datetimeindex = pd.date_range('2021-10-18 07:20:32.261811624', periods=5, tz='Australia/Adelaide', freq='40S')Display DateTimeIndex −print("DateTimeIndex...", datetimeindex) Peform Ceil operation on DateTimeIndex date with seconds frequency. For seconds frequency, we have used 'S' −print("Performing ceil operation with seconds frequency...", datetimeindex.ceil(freq='S'))ExampleFollowing is the code −import pandas as pd # DatetimeIndex with period 5 and frequency as S i.e. seconds # timezone is Australia/Adelaide ... Read More

Python Pandas - How to perform ceil operation on the DateTimeIndex with minutely frequency

AmitDiwan
Updated on 19-Oct-2021 09:57:20

149 Views

To perform ceil operation on the DateTimeIndex with minutely frequency, use the DateTimeIndex.ceil() method. For minutely frequency, use the freq parameter with value ‘T’.At first, import the required libraries −import pandas as pdCreate a DatetimeIndex with period 5 and frequency as s i.e. seconds −datetimeindex = pd.date_range('2021-10-18 07:20:32.261811624', periods=5, tz='Australia/Adelaide', freq='40S')Display DateTimeIndex −print("DateTimeIndex...", datetimeindex) Performing Ceil operation on DateTimeIndex date with minute frequency. For minute frequency, we have used 'T −print("Performing ceil operation with minute frequency...", datetimeindex.ceil(freq='T'))ExampleFollowing is the code −import pandas as pd # DatetimeIndex with period 5 and frequency as s i.e. seconds # timezone is Australia/Adelaide ... Read More

Python Pandas - How to perform ceil operation on the DateTimeIndex with hourly frequency

AmitDiwan
Updated on 19-Oct-2021 09:55:57

154 Views

To perform ceil operation on the DateTimeIndex with hourly frequency, use the DateTimeIndex.ceil() method. For hourly frequency, use the freq parameter with value ‘H’.At first, import the required libraries −import pandas as pdCreate a DatetimeIndex with period 5 and frequency as min i.e. minutes −datetimeindex = pd.date_range('2021-09-29 07:20:32.261811624', periods=5, tz='Australia/Adelaide', freq='20min')Performing Ceil operation on DateTimeIndex date with hourly frequency. For hourly frequency, we have used 'H' −print("Performing ceil operation with hourly frequency...", datetimeindex.ceil(freq='H'))ExampleFollowing is the code −import pandas as pd # DatetimeIndex with period 5 and frequency as min i.e. minutes # timezone is Australia/Adelaide datetimeindex = pd.date_range('2021-09-29 07:20:32.261811624', ... Read More

Advertisements