Found 26504 Articles for Server Side Programming

Python Pandas - Return a new Index with elements of index not in other but unsort the result

AmitDiwan
Updated on 14-Oct-2021 07:21:28

139 Views

To return a new Index with elements of index not in other but unsort the result, use the difference() method. Set the sort parameter to False.At first, import the required libraries −import pandas as pdCreating two Pandas index −index1 = pd.Index([30, 10, 20, 50, 40]) index2 = pd.Index([80, 40, 60, 20, 55])Display the Pandas index1 and index2 −print("Pandas Index1...", index1) print("Pandas Index2...", index2)Get the difference of both the indexes. Results are unsorted using the "sort" parameter with value "False" −res = index1.difference(index2, sort=False) ExampleFollowing is the code −import pandas as pd # Creating two Pandas index index1 = pd.Index([30, ... Read More

Python Pandas - Return a new Index with elements of index not in other and get the difference

AmitDiwan
Updated on 14-Oct-2021 07:19:39

304 Views

To return a new Index with elements of index not in other and get the difference, use the index1.difference(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, 40, 60, 20, 55])Display the Pandas index1 and index2print("Pandas Index1...", index1) print("Pandas Index2...", index2)Get the difference of both the indexes −res = index1.difference(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, 40, 60, 20, 55]) # Display the Pandas ... Read More

Python Pandas - Form the Union of two Index objects with different datatypes

AmitDiwan
Updated on 14-Oct-2021 07:16:14

388 Views

To form the Union of two Index objects with different datatypes, 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(['p', 'q', 'r', 's', 't', 'u'])Display the Pandas index1 and index2 −print("Pandas Index1...", index1) print("Pandas Index2...", index2)Perform union of mismatched datatypes −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(['p', 'q', 'r', 's', 't', 'u']) # Display the Pandas index1 and index2 print("Pandas ... Read More

Python Pandas - Get the second component of the Period

AmitDiwan
Updated on 14-Oct-2021 07:12:34

105 Views

To get the second component of the Period, use the period.second property. At first, import the required libraries −import pandas as pdThe pandas.Period represents a period of time. Ccreating two Period objectsperiod1 = pd.Period("2020-09-23 05:55:30") period2 = pd.Period(freq="S", year = 2021, month = 7, day = 16, hour = 2, minute = 35, second = 10)Display the Period objectsprint("Period1...", period1) print("Period2...", period2)Get the seconds from two Period objectsres1 = period1.second res2 = period2.secondExampleFollowing 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 05:55:30") period2 = ... Read More

Python Pandas - Form the Union of two Index objects but do not sort the result

AmitDiwan
Updated on 14-Oct-2021 07:13:36

290 Views

To form the intersection of two Index objects, use the index1.intersection(index2) method in Pandas. To avoid sorting the result, use the sort parameter and set it to False.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. We have used the "sort" parameter with value ‘False’ to unsort the results −res = index1.union(index2, sort=False) ExampleFollowing is the code −import pandas as pd # Creating two Pandas index index1 = pd.Index([10, ... Read More

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

AmitDiwan
Updated on 14-Oct-2021 07:11:14

489 Views

To get the quarter of the year component of the Period, use the period.quarter property. At first, import the required libraries −import pandas as pdThe pandas.Period represents a period of time. Creating two Period objectsperiod1 = pd.Period("2020-02-27 08:32:48") period2 = pd.Period(freq="M", year = 2021, month = 8, day = 16, hour = 2, minute = 35)Display the Period objectsprint("Period1...", period1) print("Period2...", period2)Get the quarter of the year from two Period objectsres1 = period1.quarter res2 = period2.quarterResult is based on the following quarters of an yearQuarter 1 = 1st January to 31st March Quarter 2 = 1st April to 30th June Quarter ... Read More

Python Pandas - Get the month of the year component of the Period

AmitDiwan
Updated on 14-Oct-2021 07:09:49

308 Views

To get the month of the year component of the Period, use the period.month property. At first, import the required libraries −import pandas as pdThe pandas.Period represents a period of time. Creating two Period objectsperiod1 = pd.Period("2020-09-23 05:55:30") period2 = pd.Period(freq="M", year = 2021, month = 8, day = 16, hour = 2, minute = 35)Display the Period objectsprint("Period1...", period1) print("Period2...", period2)Get the month of the year from two Period objectsres1 = period1.month res2 = period2.monthExampleFollowing 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 ... Read More

Python Pandas - Get the minute of the hour component of the Period

AmitDiwan
Updated on 14-Oct-2021 07:08:37

99 Views

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

Python Pandas - Check whether the year is a leap year from the Period object

AmitDiwan
Updated on 14-Oct-2021 07:04:43

229 Views

To check whether the year is a leap year from the Period object, use the period.is_leap_year property. At first, import the required libraries −import pandas as pdThe pandas.Period represents a period of time. Creating two Period objectsperiod1 = pd.Period("2020-09-23 05:55:30") period2 = pd.Period(freq="Y", year = 2021, month = 7, day = 16, hour = 2, minute = 35)Display the Period objectsprint("Period1...", period1) print("Period2...", period2)Check whether the year is a leap yearres1 = period1.is_leap_year res2 = period2.is_leap_yearExampleFollowing 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 ... Read More

Python Pandas - Get the hour of the day component of the Period

AmitDiwan
Updated on 14-Oct-2021 07:02:54

127 Views

To get the hour of the day component of the Period, use the period.hour 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 05:55:30") period2 = pd.Period(freq="H", year = 2021, month = 7, day = 16, hour = 2, minute = 35)Get the hour of the day from two Period objects −res1 = period1.hour res2 = period2.hourExampleFollowing 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 05:55:30") period2 = pd.Period(freq="H", year ... Read More

Advertisements