
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10476 Articles for Python

132 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

146 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

113 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

106 Views
To check whether the date in DateTimeIndex is the first day of the month, use the DateTimeIndex.is_month_start 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-9-21 02:30:50', periods=6, tz='Australia/Adelaide', freq='5D') Display DateTimeIndex −print("DateTimeIndex...", datetimeindex)Check whether the date in DateTimeIndex is the first day of the month −print("Check whether the date in DateTimeIndex is the first day of the month...", datetimeindex.is_month_start)ExampleFollowing is the code −import pandas as pd # DatetimeIndex with period 6 and frequency as D i.e. days # The ... Read More

665 Views
Suppose we have a list of numbers called nums. Now consider a function say f(i) which deletes the element at index i and then returns true or false, depending the resulting list's sum of even index values is same as the sum of odd index values or not. So we need the number of indexes for which f would return true.So, if the input is like nums = [6, 8, 5, 2, 3], then the output will be 2 becuase, if we remove 8, the array will be [6, 5, 2, 3], the odd and even index elements sum is ... Read More

246 Views
To extract the frequency object as a string from the DateTimeIndex, use the DateTimeIndex.freqstr property in Pandas.At first, import the required libraries −import pandas as pdCreate a DatetimeIndex with period 6 and frequency as D i.e. day −datetimeindex = pd.date_range('2021-10-20 02:30:50', periods=6, tz='Australia/Adelaide', freq='D') Display DateTimeIndex −print("DateTimeIndex...", datetimeindex)Display DateTimeIndex frequency as a string −print("DateTimeIndex frequency as string...", datetimeindex.freqstr) ExampleFollowing is the code −import pandas as pd # DatetimeIndex with period 6 and frequency as D i.e. 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...", datetimeindex) # display DateTimeIndex ... Read More

2K+ Views
To extract the frequency from the DateTimeIndex, use the DateTimeIndex.freq property in Pandas.At first, import the required libraries −import pandas as pdCreate a DatetimeIndex with period 6 and frequency as D i.e. 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...", datetimeindex)Display DateTimeIndex frequency −print("DateTimeIndex frequency...", datetimeindex.freq) ExampleFollowing is the code −import pandas as pd # DatetimeIndex with period 6 and frequency as D i.e. 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...", datetimeindex) # display DateTimeIndex frequency print("DateTimeIndex frequency...", datetimeindex.freq)OutputThis will ... Read More

161 Views
Suppose we have a binary matrix. Here 1 represents land and 0 represents water. From any land we can move up, down, left or right but not diagonally to another land cell or go off the matrix. We have to find the number of land cells from which we cannot go off the matrix.So, if the input is like0001011001100001then the output will be 4, as There's 4 land squares in the middle from which we cannot walk off the matrix.To solve this, we will follow these steps −q := a list of pairs (i, j) for each row i and ... Read More

1K+ Views
To extract the timezone from the DateTimeIndex with specific time series frequency, use the DateTimeIndex.tz property.At first, import the required libraries −import pandas as pdCreate a DatetimeIndex with period 6 and frequency as D i.e. day. 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...", datetimeindex)Get the timezone −print("Get the timezone..", datetimeindex.tz) ExampleFollowing is the code −import pandas as pd # DatetimeIndex with period 6 and frequency as D i.e. day # 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...", datetimeindex) # display DateTimeIndex frequency ... Read More

2K+ Views
To extract the quarter of the date from the DateTimeIndex with specific time series frequency, use the DateTimeIndex.quarter.At first, import the required libraries −import pandas as pdCreate a DatetimeIndex with period 6 and frequency as M i.e. Month. The timezone is Australia/Sydney −datetimeindex = pd.date_range('2021-10-20 02:30:50', periods=6, tz='Australia/Sydney', freq='2M') Display DateTimeIndex frequency −print("DateTimeIndex frequency...", datetimeindex.freq)Get the quarter of the date −print("Get the quarter of the date..", datetimeindex.quarter) Result is based on the following quarters of an year −Quarter 1 = 1st January to 31st March Quarter 2 = 1st April to 30th June Quarter 3 = 1st July to 30th ... Read More