Found 10476 Articles for Python

Python Pandas - Return the microseconds from Timedelta object

Arnab Chakraborty
Updated on 13-Oct-2021 07:43:12

192 Views

To return the microseconds from Timedelta object, use the timedelta.microseconds property. At first, import the required libraries −import pandas as pdTimeDeltas is Python’s standard datetime library uses a different representation timedelta’s. Create a Timedelta objecttimedelta = pd.Timedelta('7 days 20 min 15 s 35 ms') Return the microseconds valuetimedelta.microsecondsExampleFollowing is the code import pandas as pd # TimeDeltas is Python’s standard datetime library uses a different representation timedelta’s # create a Timedelta object timedelta = pd.Timedelta('7 days 20 min 15 s 35 ms') # display the Timedelta print("Timedelta...", timedelta) # return the microseconds value res = timedelta.microseconds ... Read More

Python - Return the maximum value of the Pandas Index

AmitDiwan
Updated on 13-Oct-2021 07:43:59

437 Views

To return the maximum value of the Pandas Index, use the index.max() method. At first, import the required libraries -import pandas as pdCreating Pandas indexindex = pd.Index([10, 20, 70, 40, 90, 50, 25, 30]) Display the Pandas index −print("Pandas Index...", index)Get the maximum value −print("Maximum value..", index.max()) ExampleFollowing is the code −import pandas as pd # Creating Pandas index index = pd.Index([10, 20, 70, 40, 90, 50, 25, 30]) # Display the Pandas index print("Pandas Index...", index) # Return the number of elements in the Index print("Number of elements in the index...", index.size) # Return the ... Read More

Python Pandas - Return the minimum value of the Timedelta object

Arnab Chakraborty
Updated on 13-Oct-2021 07:41:45

530 Views

To return the maximum value of the Timedelta object, timedelta.min property. At first, import the required libraries −import pandas as pdTimeDeltas is Python’s standard datetime library uses a different representation timedelta’s. Create a Timedelta objecttimedelta = pd.Timedelta('2 days 1 min 15 s 20 ns') Return the minimum valuetimedelta.minExampleFollowing is the code import pandas as pd # TimeDeltas is Python’s standard datetime library uses a different representation timedelta’s # create a Timedelta object timedelta = pd.Timedelta('2 days 1 min 15 s 20 ns') # display the Timedelta print("Timedelta...", timedelta) # return the minimum value res = timedelta.min ... Read More

Python - Return the minimum value of the Pandas Index

AmitDiwan
Updated on 13-Oct-2021 07:40:13

402 Views

To return the minimum value of the Pandas Index, use the index.min() method. At first, import the required libraries -import pandas as pdCreating Pandas index −index = pd.Index([10.5, 20.4, 40.5, 25.6, 5.7, 6.8, 30.8, 50.2]) Display the Pandas index −print("Pandas Index...", index)Get the minimum value −print("Minimum value..", index.min()) ExampleFollowing is the code −import pandas as pd # Creating Pandas index index = pd.Index([10.5, 20.4, 40.5, 25.6, 5.7, 6.8, 30.8, 50.2]) # Display the Pandas index print("Pandas Index...", index) # Return the number of elements in the Index print("Number of elements in the index...", index.size) # Return ... Read More

Python Pandas - Return the maximum value of the Timedelta object

Arnab Chakraborty
Updated on 13-Oct-2021 07:39:45

724 Views

To return the maximum value of the Timedelta object, timedelta.max property. At first, import the required libraries −import pandas as pdCreate a Timedelta objecttimedelta = pd.Timedelta('5 days 1 min 45 s 40 ns') Return the maximum valuetimedelta.maxExampleFollowing is the code import pandas as pd # TimeDeltas is Python’s standard datetime library uses a different representation timedelta’s # create a Timedelta object timedelta = pd.Timedelta('5 days 1 min 45 s 40 ns') # display the Timedelta print("Timedelta...", timedelta) # return the maximum value res = timedelta.max # display the maximum value print("Timedelta (max value)...", res)OutputThis will produce ... Read More

Python - Check if the Pandas Index is of the object dtype

AmitDiwan
Updated on 13-Oct-2021 07:38:02

687 Views

To check if the Pandas Index is of the object dtype, use the index.is_object() method. At first, import the required libraries -import pandas as pdCreating Pandas index −index = pd.Index(["Electronics", 6, 10.5, "Accessories", 25.6, 30]) Display the Pandas index −print("Pandas Index...", index)Check whether index values has object dtype −print("Is the Index of object dtype?", index.is_object()) ExampleFollowing is the code −import pandas as pd # Creating Pandas index index = pd.Index(["Electronics", 6, 10.5, "Accessories", 25.6, 30]) # Display the Pandas index print("Pandas Index...", index) # Return the number of elements in the Index print("Number of elements in the ... Read More

Python Pandas - Get the timedelta in nanoseconds for internal compatibility

Arnab Chakraborty
Updated on 13-Oct-2021 07:37:24

910 Views

Use the timedelta.delta property in Pandas to get the timedelta in nanoseconds for internal compatibility.At first, import the required libraries −import pandas as pdTimeDeltas is Python’s standard datetime library uses a different representation timedelta’s. Create a Timedelta objecttimedelta = pd.Timedelta('5 days 1 min 45 s 40 ns') Return the timedelta in nanosecondstimedelta.deltaExampleFollowing is the code import pandas as pd # TimeDeltas is Python’s standard datetime library uses a different representation timedelta’s # create a Timedelta object timedelta = pd.Timedelta('5 days 1 min 45 s 40 ns') # display the Timedelta print("Timedelta...", timedelta) # return the timedelta in ... Read More

Python - Check if the Pandas Index only consists of numeric data

AmitDiwan
Updated on 13-Oct-2021 07:32:57

611 Views

To check if the Pandas Index only consists of numeric data, use the index.is_numeric() method. At first, import the required libraries -import pandas as pd import numpy as npCreating Pandas index with integer, float and NaNsindex = pd.Index([5, 10.2, 25, 50, 75.2, 100, np.nan]) Display the Pandas index −print("Pandas Index...", index)Check whether index values has only numeric data. Numeric data includes integer, floats and NaNs −index.is_numeric() ExampleFollowing is the code −import pandas as pd import numpy as np # Creating Pandas index with integer, float and NaNs index = pd.Index([5, 10.2, 25, 50, 75.2, 100, np.nan]) # Display ... Read More

Python Pandas - Get the number of days from TimeDelta

Arnab Chakraborty
Updated on 13-Oct-2021 07:32:57

9K+ Views

To get the number of days from TimeDelta, use the timedelta.days property in Pandas. At first, import the required libraries −import pandas as pdTimeDeltas is Python’s standard datetime library uses a different representation timedelta’s. Create a Timedelta objecttimedelta = pd.Timedelta('5 days 1 min 45 s') Return the number of daystimedelta.daysExampleFollowing is the code import pandas as pd # TimeDeltas is Python’s standard datetime library uses a different representation timedelta’s # create a Timedelta object timedelta = pd.Timedelta('5 days 1 min 45 s') # display the Timedelta print("Timedelta...", timedelta) # return the number of days res = timedelta.days ... Read More

Python Pandas - Return a components namedtuple-like

Arnab Chakraborty
Updated on 13-Oct-2021 07:31:07

162 Views

To return a components namedtuple-like, use the timedelta.components. At first, import the required libraries −import pandas as pdTimeDeltas is Python’s standard datetime library uses a different representation timedelta’s. Create a Timedelta objecttimedelta = pd.Timedelta('1 days 10 min 20 s') Return a components namedtuple-liketimedelta.componentsExampleFollowing is the code import pandas as pd # TimeDeltas is Python’s standard datetime library uses a different representation timedelta’s # create a Timedelta object timedelta = pd.Timedelta('1 days 10 min 20 s') # display the Timedelta print("Timedelta...", timedelta) # return a components namedtuple-like res = timedelta.components # display the component print("Component...", res)OutputThis will ... Read More

Advertisements