Found 26504 Articles for Server Side Programming

Python Pandas - Return the string alias of the Time series frequency applied on the given Period object

AmitDiwan
Updated on 14-Oct-2021 07:01:10

127 Views

To return the string alias of the Time series frequency applied on the given Period object, use the period.freqstr property.At first, import the required libraries −import pandas as pdThe pandas.Period represents a period of time. Creating two Period objects −period1 = pd.Period("2020-09-23 03:55:20") period2 = pd.Period(freq="Y", year = 2021, month = 2, day = 14, hour = 2, minute = 35)Display the Period objects −print("Period1...", period1) print("Period2...", period2)Get the string alias of the frequency −res1 = period1.freqstr res2 = period2.freqstrExampleFollowing is the code −import pandas as pd # The pandas.Period represents a period of time # creating two Period ... Read More

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

AmitDiwan
Updated on 14-Oct-2021 06:59:32

208 Views

To find the end time for the given Period object, use the period.end_time property.At first, import the required libraries −import pandas as pdThe pandas.Period represents a period of time. Creating two Period objects −period1 = pd.Period("2020-09-23 03:55:20") period2 = pd.Period(freq="T", year = 2021, month = 2, day = 14, hour = 2, minute = 35)Display the Period objects −print("Period1...", period1) print("Period2...", period2)Get the end time from two Period objects −res1 = period1.end_time res2 = period2.end_timeExampleFollowing is the code −import pandas as pd # The pandas.Period represents a period of time # creating two Period objects period1 = pd.Period("2020-09-23 03:55:20") ... Read More

Python Pandas - Get the frequency for the given Period object

AmitDiwan
Updated on 14-Oct-2021 06:57:23

463 Views

To get the frequency for the given Period object, use the period.freq property.At first, import the required libraries −import pandas as pdThe pandas.Period represents a period of time. Creating two Period objects −period1 = pd.Period("2020-09-23 03:55:20") period2 = pd.Period(freq="T", year = 2021, month = 2, day = 14, hour = 2, minute = 35)Display the Period objects −print("Period1...", period1) print("Period2...", period2)Get the frequency from two Period objects −res1 = period1.freq res2 = period2.freqExampleFollowing is the code −import pandas as pd # The pandas.Period represents a period of time # creating two Period objects period1 = pd.Period("2020-09-23 03:55:20") period2 = pd.Period(freq="T", ... Read More

Python Pandas - Form the Union of two Index objects

AmitDiwan
Updated on 14-Oct-2021 06:55:11

144 Views

To form the Union of two Index objects, use the index1.union(index2) method in Pandas. At first, import the required libraries −import pandas as pdCreating two Pandas index −index1 = pd.Index([10, 20, 30, 40, 50]) index2 = pd.Index([80, 65, 60, 70, 55])Display the Pandas index1 and index2 −print("Pandas Index1...", index1) print("Pandas Index2...", index2)Perform union −res = index1.union(index2) ExampleFollowing is the code −import pandas as pd # Creating two Pandas index index1 = pd.Index([10, 20, 30, 40, 50]) index2 = pd.Index([80, 65, 60, 70, 55]) # Display the Pandas index1 and index2 print("Pandas Index1...", index1) print("Pandas Index2...", index2) # ... Read More

Python Pandas - Get the total number of days of the month that the Period falls in

AmitDiwan
Updated on 14-Oct-2021 06:55:17

712 Views

To get the total number of days of the month that a Period falls on, use the period.daysinmonth property.At first, import the required libraries −import pandas as pdThe pandas.Period represents a period of time. Creating two Period objects −period1 = pd.Period("2020-09-23") period2 = pd.Period(freq="D", year = 2021, month = 2, day = 14, hour = 2, minute = 35)Display the Period objects −print("Period1...", period1) print("Period2...", period2)Get the days in the month from two Period objects −res1 = period1.daysinmonth res2 = period2.daysinmonthExampleFollowing is the code −import pandas as pd # The pandas.Period represents a period of time # creating two ... Read More

Python Pandas - Form the intersection of two Index objects and sort the result

AmitDiwan
Updated on 14-Oct-2021 06:52:58

668 Views

To form the intersection of two Index objects, use the index1.intersection(index2) method in Pandas. To sort the result, use the sort parameter.At first, import the required libraries −import pandas as pdCreating Pandas index1 and index2 −index1 = pd.Index([4, 3, 2, 1]) index2 = pd.Index([8, 2, 6, 4])Display the Pandas index1 and index2print("Pandas Index1...", index1) print("Pandas Index2...", index2)Perform intersection. The results are sorted using the "sort" parameterres = index1.intersection(index2, sort=None) ExampleFollowing is the code −import pandas as pd # Creating Pandas index1 and index2 index1 = pd.Index([4, 3, 2, 1]) index2 = pd.Index([8, 2, 6, 4]) # Display the ... Read More

Python Pandas - Get the Day of the year from Period object

AmitDiwan
Updated on 14-Oct-2021 06:52:27

202 Views

To get day of the year from Period object, use the period.dayofyear property.At first, import the required libraries −import pandas as pdThe pandas.Period represents a period of time. Creating two Period objects −period1 = pd.Period("2020-09-23") period2 = pd.Period(freq="D", year = 2021, month = 7, day = 16, hour = 2, minute = 35)Display the Period objects −print("Period1...", period1) print("Period2...", period2)Get the day of the year from two Period objects −res1 = period1.dayofyear res2 = period2.dayofyearExampleFollowing is the code −import pandas as pd # The pandas.Period represents a period of time # creating two Period objects period1 = pd.Period("2020-09-23") period2 = ... Read More

Python Pandas - Get the Day of the week the period lies in

AmitDiwan
Updated on 14-Oct-2021 06:51:33

177 Views

To get day of the week that a Period falls on, use the period.dayofweek propertyAt first, import the required libraries −import pandas as pdThe pandas.Period represents a period of time. Creating two Period objects −period1 = pd.Period("2021-09-18") period2 = pd.Period(freq ='D', year = 2021, month = 9, day = 22, hour = 4, minute = 55)Display the Period objects −print("Period1...", period1) print("Period2...", period2)Get the day of week from two Period objects −res1 = period1.dayofweek res2 = period2.dayofweekExampleFollowing is the code −import pandas as pd # The pandas.Period represents a period of time # creating two Period objects period1 = ... Read More

Python Pandas - Form the intersection of two Index objects

AmitDiwan
Updated on 14-Oct-2021 06:50:43

230 Views

To form the intersection of two Index objects, use the index1.intersection(index2) method in Pandas. At first, import the required libraries −import pandas as pdCreating two Pandas index −index1 = pd.Index([10, 20, 30, 40, 50]) index2 = pd.Index([80, 65, 60, 70, 55])Display the Pandas index1 and index2 −print("Pandas Index1...", index1) print("Pandas Index2...", index2)Perform intersection −res = index1.intersection(index2) ExampleFollowing is the code −import pandas as pd # Creating two Pandas index index1 = pd.Index([10, 20, 30, 40, 50]) index2 = pd.Index([80, 65, 60, 70, 55]) # Display the Pandas index1 and index2 print("Pandas Index1...", index1) print("Pandas Index2...", index2) # ... Read More

Python Pandas - Get day of the month that a Period falls on

AmitDiwan
Updated on 14-Oct-2021 06:49:36

206 Views

To get day of the month that a Period falls on, use the period.day property.At first, import the required libraries −import pandas as pdThe pandas.Period represents a period of time. Creating two Period objects−period1 = pd.Period("2021-09-18") period2 = pd.Period(freq ='D', year = 2021, month = 9, day = 22, hour = 4, minute = 55)Get the day of the month from two Period objects −res1 = period1.day res2 = period2.dayExampleFollowing is the code −import pandas as pd # The pandas.Period represents a period of time # creating two Period objects period1 = pd.Period("2021-09-18") period2 = pd.Period(freq ='D', year = 2021, ... Read More

Advertisements