
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10476 Articles for Python

231 Views
To return the seconds from Timedelta object, use the timedelta.seconds 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('10 s 15 ms 33 ns') Display the Timedeltaprint("Timedelta...", timedelta)Return the seconds valuetimedelta.seconds 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('10 s 15 ms 33 ns') # display the Timedelta print("Timedelta...", timedelta) # return the seconds value res = timedelta.seconds ... Read More

257 Views
To replace index values where the condition is False, use the index.isin() method in Pandas. At first, import the required libraries −import pandas as pdCreating Pandas index −index = pd.Index(['Electronics', 'Accessories', 'Decor', 'Books', 'Toys'], name ='Products') Display the Pandas index −print("Pandas Index...", index)Replace values where condition is False. Here, except the 'Decor', every other element gets replaced −print("Replace index vales where condition is False...", index.where(index.isin(['Decor']), 'Miscellaneous'))ExampleFollowing is the code −import pandas as pd # Creating Pandas index index = pd.Index(['Electronics', 'Accessories', 'Decor', 'Books', 'Toys'], name ='Products') # Display the Pandas index print("Pandas Index...", index) # Return the ... Read More

206 Views
To return the nanoseconds 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. Set string input for microseconds using unit 'us'. Create a Timedelta objecttimedelta = pd.Timedelta('12 min 40 us') Display the Timedeltaprint("Timedelta...", timedelta)Return the microseconds valuetimedelta.microseconds ExampleFollowing is the code import pandas as pd # TimeDeltas is Python’s standard datetime library uses a different representation timedelta’s # set string input for microseconds using unit 'us' # create a Timedelta object timedelta = pd.Timedelta('12 min 40 us') # Display the ... Read More

173 Views
To repeat each element of a Pandas Series in a dissimilar way, use the index.repeat() method. At first, import the required libraries -import pandas as pdCreating Pandas index −index = pd.Index(['Car', 'Bike', 'Airplane', 'Ship'], name ='Transport') Display the Pandas index −print("Pandas Index...", index)Repeat each element of the index in a dissimilar way −print("Result after repeating each index element in a different way...", index.repeat([2, 3, 5, 7]))ExampleFollowing is the code −import pandas as pd # Creating Pandas index index = pd.Index(['Car', 'Bike', 'Airplane', 'Ship'], name ='Transport') # Display the Pandas index print("Pandas Index...", index) # Return the number ... Read More

111 Views
To return the nanoseconds 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. Set integer input for microseconds using unit 'us'. Create a Timedelta objecttimedelta = pd.Timedelta(55, unit ='us') Display the Timedeltaprint("Timedelta...", timedelta)Return the microseconds valuetimedelta.microseconds ExampleFollowing is the code import pandas as pd # TimeDeltas is Python’s standard datetime library uses a different representation timedelta’s # set integer input for microseconds using unit 'us' # create a Timedelta object timedelta = pd.Timedelta(55, unit ='us') # display the Timedelta print("Timedelta...", ... Read More

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

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

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

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

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