Timestamp.isoformat in Pandas Example
It will print the original Timestamp object, convert it to the ISO 8601 format, and print the ISO 8601 timestamp. It also produces a Timestamp object with a specified date, time, and timezone.
Python3
import pandas as pd # Create a Timestamp object in ISO format time_stamp_obj = pd.Timestamp( '2015-06-26 07:35:00' , tz = 'Asia/Kolkata' ) # Print the Timestamp object print ( "Timestamp Object:" , time_stamp_obj) # Convert the Timestamp object to ISO format iso_8601 = time_stamp_obj.isoformat() print ( "ISO 8601 Format:" , iso_8601) |
Output:
Timestamp Object: 2015-06-26 07:35:00+05:30
ISO 8601 Format: 2015-06-26T07:35:00+05:30
Example 1
Use Timestamp.isoformat()
function to convert the date in the given Timestamp object to ISO format.
Python3
# importing pandas as pd import pandas as pd # Create the Timestamp object ts = pd.Timestamp(year = 2011 , month = 11 , day = 21 , hour = 10 , second = 49 , tz = 'US/Central' ) # Print the Timestamp object print (ts) |
Output :
2011-11-21 10:00:49-06:00
Now we will use the Timestamp.isoformat()
function to convert the date in the given Timestamp object to ISO format.
Python3
# convert to ISO format ts.isoformat() |
Output:
'2011-11-21T10:00:49-06:00'
As we can see in the output, the Timestamp.isoformat()
function has returned the date in the ISO format.
Example 2
Use Timestamp.isoformat()
function to convert the date in the given Timestamp object to ISO format.
Python3
# importing pandas as pd import pandas as pd # Create the Timestamp object ts = pd.Timestamp(year = 2009 , month = 5 , day = 31 , hour = 4 , second = 49 , tz = 'Europe/Berlin' ) # Print the Timestamp object print (ts) |
Output:
2009-05-31 04:00:49+02:00
Now we will use the Timestamp.isoformat()
function to convert the date in the given Timestamp object to ISO format.
Python3
# convert to ISO format ts.isoformat() |
Output:
'2009-05-31T04:00:49+02:00'
As we can see in the output, the Timestamp.isoformat()
function has returned the date in the ISO format.
Python | Pandas Timestamp.isoformat
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. Pandas Timestamp objects represent date and time values, making them essential for working with temporal data.
Contact Us