Programming Articles - Page 965 of 3363

Python Pandas - Detect the frequency of the given DatetimeIndex object

AmitDiwan
Updated on 18-Oct-2021 12:56:45

227 Views

To detect the frequency of the given DatetimeIndex object, use the DateTimeIndex.inferred_freq property.At first, import the required libraries −import pandas as pdCreate a DatetimeIndex with period 5 and frequency as Y i.e. years. The timezone is Australia/Adelaide −datetimeindex = pd.date_range('2021-10-30 02:30:50', periods=5, tz='Australia/Adelaide', freq='3Y') Display DateTimeIndex −print("DateTimeIndex...", datetimeindex)Display DateTimeIndex frequency −print("DateTimeIndex frequency...", datetimeindex.freq) ExampleFollowing is the code −import pandas as pd # DatetimeIndex with period 5 and frequency as Y i.e. years # The timezone is Australia/Adelaide datetimeindex = pd.date_range('2021-10-30 02:30:50', periods=5, tz='Australia/Adelaide', freq='3Y') # display DateTimeIndex print("DateTimeIndex...", datetimeindex) # display DateTimeIndex frequency print("DateTimeIndex frequency...", datetimeindex.freq) ... Read More

Python Pandas - Indicate whether the date in DateTimeIndex belongs to a leap year or not

AmitDiwan
Updated on 18-Oct-2021 12:54:46

191 Views

To check whether the date in DateTimeIndex belongs to a leap year, use the DateTimeIndex.is_leap_year propertyAt first, import the required libraries −import pandas as pdCreate a DatetimeIndex with period 6 and frequency as Y i.e. years −datetimeindex = pd.date_range('2021-12-30 02:30:50', periods=6, tz='Australia/Adelaide', freq='3Y') Display DateTimeIndex −print("DateTimeIndex...", datetimeindex)Check whether the date in DateTimeIndex is a leap year or not −print("Check whether the date in DateTimeIndex belongs to a leap year or not...", datetimeindex.is_leap_year)ExampleFollowing is the code −import pandas as pd # DatetimeIndex with period 6 and frequency as Y i.e. years # The timezone is Australia/Adelaide datetimeindex = pd.date_range('2021-12-30 02:30:50', ... Read More

Minimum number of moves to escape maze matrix in Python

Arnab Chakraborty
Updated on 18-Oct-2021 12:57:28

1K+ Views

Suppose we have a binary matrix, where 0 is representing an empty cell, and 1 is a wall. If we start from top left corner (0, 0), we have to find the minimum number of cells it would take to get to bottom right corner (R-1, C-1) Here R is number of rows and C is number of columns. If we cannot find any answer, return -1.So, if the input is like00010001100001111000then the output will be 8 because, we can select path like −00010001100001111000To solve this, we will follow these steps −R := number of rowsC := number of columnsq ... Read More

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

AmitDiwan
Updated on 18-Oct-2021 12:52:31

169 Views

To check whether the date in DateTimeIndex is the last day of the year, use the DateTimeIndex.is_year_end property.At first, import the required libraries −import pandas as pdCreate a DatetimeIndex with period 6 and frequency as D i.e. days −datetimeindex = pd.date_range('2021-12-25 02:30:50', periods=6, tz='Australia/Adelaide', freq='2D') Display DateTimeIndex −print("DateTimeIndex...", datetimeindex)Check whether the date in DateTimeIndex is the last day of the year −print("Check whether the date in DateTimeIndex is the last day of the year...", datetimeindex.is_year_end)ExampleFollowing is the code −import pandas as pd # DatetimeIndex with period 6 and frequency as D i.e. days # The timezone is Australia/Adelaide datetimeindex ... Read More

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

AmitDiwan
Updated on 18-Oct-2021 12:49:48

176 Views

To check whether the date in DateTimeIndex is the first day of the year, use the DateTimeIndex.is_year_start property.At first, import the required libraries −import pandas as pdCreate a DatetimeIndex with period 6 and frequency as D i.e. days −datetimeindex = pd.date_range('2021-12-30 02:30:50', periods=6, tz='Australia/Adelaide', freq='1D') Display DateTimeIndex −print("DateTimeIndex...", datetimeindex)Check whether the date in DateTimeIndex is the first day of the year −print("Check whether the date in DateTimeIndex is the first day of the year...", datetimeindex.is_year_start)ExampleFollowing is the code −import pandas as pd # DatetimeIndex with period 6 and frequency as D i.e. days # The timezone is Australia/Adelaide datetimeindex ... Read More

Program to find number of quadruples for which product of first and last pairs are same in Python

Arnab Chakraborty
Updated on 18-Oct-2021 12:51:58

292 Views

Suppose we have a list of numbers called nums, with unique positive numbers nums. We have to find the number of quadruples like (a, b, c, d) from nums such that a*b = c*d, a, b, c and d all are distinct elements of nums.So, if the input is like nums = [3, 6, 4, 8], then the output will be 8, because the quadruples are [[3, 8, 6, 4], [3, 8, 4, 6], [8, 3, 6, 4], [8, 3, 4, 6], [6, 4, 3, 8], [4, 6, 3, 8], [6, 4, 8, 3], [4, 6, 8, 3]].To solve this, ... Read More

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

AmitDiwan
Updated on 18-Oct-2021 12:48:31

288 Views

To check whether the date in DateTimeIndex is the last day of the quarter, use the DateTimeIndex.is_quarter_end property.At first, import the required libraries −import pandas as pdCreate a DatetimeIndex with period 6 and frequency as D i.e. days. The timezone is Australia/Adelaide −datetimeindex = pd.date_range('2021-6-15 02:30:50', periods=6, tz='Australia/Adelaide', freq='15D') Display DateTimeIndex −print("DateTimeIndex...", datetimeindex)Check whether the date in DateTimeIndex is the last day of the quarter −print("Check whether the date in DateTimeIndex is the last day of the quarter...", datetimeindex.is_quarter_end)ExampleFollowing is the code −import pandas as pd # DatetimeIndex with period 6 and frequency as D i.e. days # The ... Read More

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

AmitDiwan
Updated on 18-Oct-2021 12:47:02

148 Views

To check whether the date in DateTimeIndex is the first day of the quarter, use the DateTimeIndex.is_quarter_start property.At first, import the required libraries −import pandas as pdCreate a DatetimeIndex with period 6 and frequency as D i.e. days −datetimeindex = pd.date_range('2021-10-1 02:30:50', periods=6, tz='Australia/Adelaide', freq='30D') Display DateTimeIndex −print("DateTimeIndex...", datetimeindex)Check whether the date in DateTimeIndex is the first day of the quarter −print("Check whether the date in DateTimeIndex is the first day of the quarter...", datetimeindex.is_quarter_start)ExampleFollowing is the code −import pandas as pd # DatetimeIndex with period 6 and frequency as D i.e. days # The timezone is Australia/Adelaide datetimeindex ... Read More

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

AmitDiwan
Updated on 18-Oct-2021 12:45:40

167 Views

To check whether the date in DateTimeIndex is the last day of the month, use the DateTimeIndex.is_month_end property.At first, import the required libraries −import pandas as pdCreate a DatetimeIndex with period 6 and frequency as D i.e. days −datetimeindex = pd.date_range('2021-9-15 06:40:35', periods=6, tz='Australia/Adelaide', freq='15D') Display DateTimeIndex −print("DateTimeIndex...", datetimeindex)Check whether the date in DateTimeIndex is the last day of the month −print("Check whether the date in DateTimeIndex is the last day of the month...", datetimeindex.is_month_end)ExampleFollowing is the code −import pandas as pd # DatetimeIndex with period 6 and frequency as D i.e. days # The timezone is Australia/Adelaide datetimeindex ... 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
Updated on 18-Oct-2021 12:49:34

147 Views

Suppose we have a list of numbers called nums. The length of this list is even. Now consider an operation where we select any number in nums and update it with a value in range [1 and maximum of nums]. We have to find the minimum number of such operations required such that, for every i, nums[i] + nums[n-1-i] equals to the same number.So, if the input is like nums = [8, 6, 2, 5, 9, 2], then the output will be 2, because if we change first 2 at nums[2] to 5, and 9 at nums[4] to 4, then ... Read More

Advertisements