asm8: Timedelta is a subclass of datetime.timedelta, and it performs similarly. It’s Pandas’ version of Python’s datetime.timedelta. In most circumstances, it is interchangeable with it.
Pandas Timedelta.asm8 Attribute:
This property Timedelta.asm8 of the pandas module returns a numpy timedelta64 array view.
Syntax:
Timedelta.asm8
Parameters: It has no arguments
Return Value:
A numpy timedelta64 array view is returned by the Timedelta.asm8 of the pandas module.
Pandas Timedelta.asm8 Attribute in Python
Example1
Approach:
- Import pandas module using the import keyword.
- Pass some random Timestamp in the format(days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds) to the Timedelta() function of the pandas module to get the Timedelta object.
- Store it in a variable
- Print the above obtained Timedelta object
- Apply asm8 attribute on the above Timedelta object to get the numpy timedelta64 array view of the given Timedelta object.
-
The Exit of the Program.
Below is the implementation:
# Import pandas module using the import keyword. import pandas as pd # Pass some random Timestamp in the format(days, hours, minutes, seconds, # milliseconds, microseconds, nanoseconds) to the Timedelta() function of # the pandas module to get the Timedelta object. # Store it in a variable timedelta_obj = pd.Timedelta('7 days 10:15:08.13010') # Print the above obtained Timedelta object print("The above obtained Timedelta object:", timedelta_obj) # Apply asm8 attribute on the above Timedelta object to get the # numpy timedelta64 array view of the given Timedelta object. print("The numpy timedelta64 array view of the given Timedelta object:") print(timedelta_obj.asm8)
Output:
The above obtained Timedelta object: 7 days 10:15:08.130100 The numpy timedelta64 array view of the given Timedelta object: 641708130100000 nanoseconds
Example2
Here only days, minutes are passed as arguments.
Approach:
- Import pandas module using the import keyword.
- Pass some random Timestamp in the format(days, minutes) to the Timedelta() function of the pandas module to get the Timedelta object.
- Store it in a variable
- Print the above obtained Timedelta object.
- Apply asm8 attribute on the above Timedelta object to get the numpy timedelta64 array view of the given Timedelta object.
-
The Exit of the Program.
Below is the implementation:
# Import pandas module using the import keyword. import pandas as pd # Pass some random Timestamp in the format(days, minutes) to the Timedelta() # function of the pandas module to get the Timedelta object. # Store it in a variable timedelta_obj = pd.Timedelta('6 days 30 minutes') # Print the above obtained Timedelta object print("The above obtained Timedelta object:", timedelta_obj) print() # Apply asm8 attribute on the above Timedelta object to get the # numpy timedelta64 array view of the given Timedelta object. print("The numpy timedelta64 array view of the given Timedelta object:") print(timedelta_obj.asm8)
Output:
The above obtained Timedelta object: 6 days 00:30:00 The numpy timedelta64 array view of the given Timedelta object: 520200000000000 nanoseconds
Example3
# Import pandas module using the import keyword. import pandas as pd # Pass some random Timestamp in the format(days, minutes, seconds) to the Timedelta() # function of the pandas module to get the Timedelta object. # Store it in a variable timedelta_obj = pd.Timedelta(days=12, minutes=15, seconds=20) # Print the above obtained Timedelta object print("The above obtained Timedelta object:", timedelta_obj) print() # Apply asm8 attribute on the above Timedelta object to get the # numpy timedelta64 array view of the given Timedelta object. print("The numpy timedelta64 array view of the given Timedelta object:") print(timedelta_obj.asm8)
Output:
The above obtained Timedelta object: 12 days 00:15:20 The numpy timedelta64 array view of the given Timedelta object: 1037720000000000 nanoseconds