Suppose we have two lists nums1 and nums2, they are representing sensor metrics. Each list contains unique values, so a ≠ b. One of these two lists are holding accurate sensor metrics but the other one contains faulty. In the faulty list one value, that is not the last value was dropped and a wrong value was placed to the end of that list. We have to find the actual value that was dropped.So, if the input is like nums1 = [5, 10, 15] nums2 = [10, 15, 8], then the output will be 5, as first list nums1 holds ... Read More
To extract the ordinal day of year from the DateTimeIndex with specific time series frequency, use the DateTimeIndex.dayofyear propertyAt 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/Sydney', freq='D') Display DateTimeIndex −print("DateTimeIndex...", datetimeindex)Get the day of year −print("Get the ordinal day of year..", datetimeindex.dayofyear) 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) ... Read More
Suppose we have a value h and a list of numbers called blacklist. We are currently at height h, and are playing a game to move a small ball down to height 0. Now, in even rounds (starting from 0) we can move the ball 1, 2, or 4 stairs down. And in odd rounds, we can move the ball 1, 3, or 4 stairs down. Some levels are blacklisted. So if the ball reach there, it will die immediately. We have to find the number of ways the ball can move down at height 0. If the answer is ... Read More
To return numpy array of python datetime.time objects with timezone information, use the datetimeindex.timetz property.At first, import the required libraries −import pandas as pdCreate a DatetimeIndex with period 5 and frequency as us i.e. nanoseconds −datetimeindex = pd.date_range('2021-10-20 02:30:50', periods=5, tz='Australia/Sydney', freq='ns') Display DateTimeIndex −print("DateTimeIndex...", datetimeindex)Returns only the time part of Timestamp with timezone information −print("The numpy array (time part with timezone)..", datetimeindex.timetz) ExampleFollowing is the code −import pandas as pd # DatetimeIndex with period 5 and frequency as us i.e. nanoseconds # The timezone is Australia/Sydney datetimeindex = pd.date_range('2021-10-20 02:30:50', periods=5, tz='Australia/Sydney', freq='ns') # display DateTimeIndex print("DateTimeIndex...", ... Read More
To return numpy array of python datetime.time objects, use the datetimeindex.time property in Pandas.At first, import the required libraries −import pandas as pdCreate a DatetimeIndex with period 3 and frequency as us i.e. nanoseconds. The timezone is Australia/Sydney −datetimeindex = pd.date_range('2021-10-20 02:30:50', periods=3, tz='Australia/Sydney', freq='ns') Display DateTimeIndex −print("DateTimeIndex...", datetimeindex)Returns only the time part of Timestamps without timezone information −print("The numpy array (time part)..", datetimeindex.time) ExampleFollowing is the code −import pandas as pd # DatetimeIndex with period 3 and frequency as us i.e. nanoseconds # The timezone is Australia/Sydney datetimeindex = pd.date_range('2021-10-20 02:30:50', periods=3, tz='Australia/Sydney', freq='ns') # display DateTimeIndex ... Read More
To extract the nanoseconds from the DateTimeIndex with specific time series frequency, use the DateTimeIndex.nanosecond property.At first, import the required libraries −import pandas as pdCreate a DatetimeIndex with period 6 and frequency as ns i.e. nanoseconds −datetimeindex = pd.date_range('2021-10-20 02:30:50', periods=6, tz='Australia/Sydney', freq='ns') Display DateTimeIndex −print("DateTimeIndex...", datetimeindex)Get the nanoseconds −print("Getting the nanoseconds..", datetimeindex.nanosecond) ExampleFollowing is the code −import pandas as pd # DatetimeIndex with period 6 and frequency as ns i.e. nanoseconds # The timezone is Australia/Sydney datetimeindex = pd.date_range('2021-10-20 02:30:50', periods=6, tz='Australia/Sydney', freq='ns') # display DateTimeIndex print("DateTimeIndex...", datetimeindex) # display DateTimeIndex frequency print("DateTimeIndex frequency...", datetimeindex.freq) ... Read More
Suppose we have a lowercase string s. Now consider an operation, where we can delete, insert or update any character in s. We have to count minimum number of operations required to make s = (t concatenate t) for any string t.So, if the input is like s = "pqrxqsr", then the output will be 2, because, we can update the "x" with "p" and delete "s", then s is "pqrpqr", this is s = t concatenate t, for t = "pqr".To solve this, we will follow these steps −Define a function edit_distance(). This will take s1, s2m := size ... Read More
To return numpy array of python datetime.date objects, use the datetimeindex.date property in Pandas.At first, import the required libraries −import pandas as pdCreate a DatetimeIndex with period 3 and frequency as us i.e. nanoseconds −datetimeindex = pd.date_range('2021-10-20 02:30:50', periods=3, tz='Australia/Sydney', freq='ns') Display DateTimeIndex −print("DateTimeIndex...", datetimeindex)Returns only the date part of Timestamps without timezone information −print("The numpy array (date part)..", datetimeindex.date) ExampleFollowing is the code −import pandas as pd # DatetimeIndex with period 3 and frequency as us i.e. nanoseconds # The timezone is Australia/Sydney datetimeindex = pd.date_range('2021-10-20 02:30:50', periods=3, tz='Australia/Sydney', freq='ns') # display DateTimeIndex print("DateTimeIndex...", datetimeindex) # ... Read More
To extract the microsecond from the DateTimeIndex with specific time series frequency, use the DateTimeIndex.microsecond property.At first, import the required libraries −import pandas as pdCreate a DatetimeIndex with period 6 and frequency as us i.e. microseconds. The timezone is Australia/Sydney −datetimeindex = pd.date_range('2021-10-20 02:30:50', periods=6, tz='Australia/Sydney', freq='us') Display DateTimeIndex −print("DateTimeIndex...", datetimeindex)Get the microsecond −print("Getting the microseconds..", datetimeindex.microsecond) ExampleFollowing is the code −import pandas as pd # DatetimeIndex with period 6 and frequency as us i.e. microseconds # The timezone is Australia/Sydney datetimeindex = pd.date_range('2021-10-20 02:30:50', periods=6, tz='Australia/Sydney', freq='us') # display DateTimeIndex print("DateTimeIndex...", datetimeindex) # display DateTimeIndex frequency ... Read More
To extract the seconds from the DateTimeIndex with specific time series frequency, use the DateTimeIndex.second property.At first, import the required libraries −import pandas as pdCreate a DatetimeIndex with period 6 and frequency as S i.e. seconds. The timezone is Australia/Sydney −datetimeindex = pd.date_range('2021-10-20 02:30:50', periods=6, tz='Australia/Sydney', freq='S') Display DateTimeIndex −print("DateTimeIndex...", datetimeindex)Get the seconds −print("Getting the seconds..", datetimeindex.second) ExampleFollowing is the code −import pandas as pd # DatetimeIndex with period 6 and frequency as S i.e. seconds # The timezone is Australia/Sydney datetimeindex = pd.date_range('2021-10-20 02:30:50', periods=6, tz='Australia/Sydney', freq='S') # display DateTimeIndex print("DateTimeIndex...", datetimeindex) # display DateTimeIndex frequency ... Read More
 Data Structure
 Networking
 RDBMS
 Operating System
 Java
 iOS
 HTML
 CSS
 Android
 Python
 C Programming
 C++
 C#
 MongoDB
 MySQL
 Javascript
 PHP