Python | Pandas Timestamp.tzinfo

Python Methods and Functions

The Pandas attribute Timestamp.tzinfo is used to check the time zone of a given Timestamp object. If no time zone is set, "No" is returned.

Syntax: Timestamp.tzinfo

Parameters: None

Return: timezone

Example # 1: Use the Timestamp.tzinfo attribute to find the time zone of a given Timestamp.

# import pandas as pd

import pandas as pd

 
# Create Timestamp object

ts = pd.Timestamp (year = 2011 , month = 11 , day = 21 ,

hour = 10 , second = 49 , tz = 'US / Central' )

 
# Print Timestamp object

print (ts)

Output:

We will now use the Timestamp.tzinfo attribute to find the time zone for this object.

< tr>

# return time zone
ts.tzinfo

Output:

As we can see from the output, the Timestamp.tzinfo attribute returned & # 39; US / Central & # 39;, indicating that the time in this Timestamp object is based on the time zone & # 39; US / Central & # 39 ;.

Example # 2: Use the Timestamp.tzinfo to find the time zone of this Timestamp object.

Output:

< img src = "http://espressocode.top/images/boafetimalderees797376.jpg" />

We will now use the Timestamp.tzinfo attribute to find the time zone for this object.

# import pandas as pd

import pandas as pd

 
# Create Timestamp object

ts = pd.Timestamp (year = 2009 , month = 5 , day = 31

hour = 4 , second = 49 , tz = 'Europe / Berlin' )

  
# Print the Timestamp object

print (ts)

# return time zone
ts.tzinfo

Output:

As we can see from the output, the Timestamp.tzinfo attribute returned" Europe / Berlin "indicating that The time in this Timestamp is based on the "Europe / Berlin" time zone.





Tutorials