Found 26504 Articles for Server Side Programming

Python Pandas - Repeat elements of an Index

AmitDiwan
Updated on 13-Oct-2021 07:50:28

508 Views

To repeat elements of an Index, use the index.repeat() method in Pandas. Set the number of repetitions as an argument. At first, import the required libraries −import pandas as pdCreating Pandas index −index = pd.Index(['Car', 'Bike', 'Airplane', 'Ship', 'Truck', 'Suburban'], name ='Transport') Display the Pandas index −print("Pandas Index...", index)Repeat elements of the index −print("Result after repeating each index element twice...", index.repeat(2)) ExampleFollowing is the code −import pandas as pd # Creating Pandas index index = pd.Index(['Car', 'Bike', 'Airplane', 'Ship', 'Truck', 'Suburban'], name ='Transport') # Display the Pandas index print("Pandas Index...", index) # Return the number of elements ... Read More

Python Pandas - Return the nanoseconds from Timedelta object using string input

Arnab Chakraborty
Updated on 13-Oct-2021 07:48:23

126 Views

To return the nanoseconds from Timedelta object, use the timedelta.nanoseconds property. At first, import the required libraries −import pandas as pdTimeDeltas is Python’s standard datetime library uses a different representation timedelta’s. Set string input for nanoseconds using unit 'ns'. Create a Timedelta object timedelta = pd.Timedelta('10 min 40 ns')Display the Timedeltaprint("Timedelta...", timedelta) Return the nanoseconds valuetimedelta.nanosecondsExampleFollowing is the code import pandas as pd # TimeDeltas is Python’s standard datetime library uses a different representation timedelta’s # set string input for nanoseconds using unit 'ns' # create a Timedelta object timedelta = pd.Timedelta('10 min 40 ns') # display the ... Read More

Python Pandas - Return the nanoseconds from Timedelta object using integer input

Arnab Chakraborty
Updated on 13-Oct-2021 07:46:51

321 Views

To return the nanoseconds from Timedelta object, use the timedelta.nanoseconds property. At first, import the required libraries −import pandas as pdTimeDeltas is Python’s standard datetime library uses a different representation timedelta’s. Set integer input for nanoseconds using unit 'ns'. Create a Timedelta objecttimedelta = pd.Timedelta(35, unit ='ns') Return the nanoseconds valuetimedelta.nanosecondsExampleFollowing is the code import pandas as pd # TimeDeltas is Python’s standard datetime library uses a different representation timedelta’s # set integer input for nanoseconds using unit 'ns' # create a Timedelta object timedelta = pd.Timedelta(35, unit ='ns') # display the Timedelta print("Timedelta...", timedelta) # return ... Read More

Python Pandas - Alter index name

AmitDiwan
Updated on 13-Oct-2021 07:46:52

226 Views

To alter index name, use the index.rename() method in Pandas. At first, import the required libraries −import pandas as pdCreating Pandas index −index = pd.Index(['Car', 'Bike', 'Airplane', 'Ship', 'Truck', 'Suburban'], name ='Transport') Display the Pandas index −print("Pandas Index...", index)Rename the index −print("Rename the index...", index.rename('Mode_of_Transport')) ExampleFollowing is the code −import pandas as pd # Creating Pandas index index = pd.Index(['Car', 'Bike', 'Airplane', 'Ship', 'Truck', 'Suburban'], name ='Transport') # 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 dtype of ... Read More

Python Pandas - Return the nanoseconds from Timedelta object

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

140 Views

To return the microseconds from Timedelta object, use the timedelta.nanoseconds 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('4 days 10 min 25 s 15 ms 33 ns') Display the Timedeltaprint("Timedelta...", timedelta)Return the nanoseconds valuetimedelta.nanoseconds ExampleFollowing 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('4 days 10 min 25 s 15 ms 33 ns') # display the Timedelta print("Timedelta...", timedelta) # ... Read More

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

438 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

403 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

725 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

Advertisements