Python | Pandas Timedelta.asm8

Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.

Timedelta is a subclass of datetime.timedelta, and behaves in a similar manner. It is the pandas equivalent of python’s datetime.timedelta and is interchangeable with it in most cases. Timedelta.asm8 property in pandas.Timedelta is used to return a numpy timedelta64 array view.

Syntax: Timedelta.asm8



Parameters: None

Returns: numpy timedelta64 array view

Code #1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing pandas as pd 
import pandas as pd 
  
# Create the Timedelta object 
td = pd.Timedelta('3 days 06:05:01.000030'
  
# Print the Timedelta object 
print(td) 
  
print(td.asm8)

chevron_right


Output:

3 days 06:05:01.000030
281101000030000 nanoseconds

Code #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing pandas as pd 
import pandas as pd 
  
# Create the Timedelta object 
td = pd.Timedelta('1 days 7 hours'
  
# Print the Timedelta object 
print(td) 
  
print(td.asm8)

chevron_right


Output:

1 days 07:00:00
111600000000000 nanoseconds

Code #3:

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing pandas as pd 
import pandas as pd 
import datetime
  
# Create the Timedelta object 
td = pd.Timedelta(datetime.timedelta(days = 3, hours = 7, seconds = 8)) 
  
# Print the Timedelta object 
print(td) 
  
print(td.asm8)

chevron_right


Output:

3 days 07:00:08
284408000000000 nanoseconds


My Personal Notes arrow_drop_up

Recommended Posts:



    Article Tags :

    Be the First to upvote.


    Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.