Friday, November 14, 2025
HomeLanguagesPython | Pandas Timestamp.fromordinal

Python | Pandas Timestamp.fromordinal

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.fromordinal() function return a Timestamp object when passed an ordinal, the function translate and convert it to a ts object. By definition there cannot be any tz info on the ordinal itself.

Syntax :Timestamp.fromordinal()

Parameters :

ordinal : date corresponding to a proleptic Gregorian ordinal

freq : Offset which Timestamp will have

tz : Time zone for time which Timestamp will have

Return : Timestamp

Example #1: Use Timestamp.fromordinal() function to translate the given Timestamp object based on the passed ordinal value.




# 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 :

Now we will use the Timestamp.fromordinal() function to convert the given Timestamp object.




# convert the given Timestamp object
# based on the passed ordinal value
ts.fromordinal(ordinal = 733829)


Output :

As we can see in the output, the Timestamp.fromordinal() function has returned a new Timestamp object based on the passed ordinal value.

Example #2: Use Timestamp.fromordinal() function to translate the given Timestamp object based on the passed ordinal value. Also set the timezone.




# 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 :

Now we will use the Timestamp.fromordinal() function to convert the given Timestamp object.




# convert the given Timestamp object
# based on the passed ordinal value
ts.fromordinal(ordinal = 634816, tz = 'Asia / Calcutta')


Output :

As we can see in the output, the Timestamp.fromordinal() function has returned a new Timestamp object based on the passed ordinal value. The function has also set the timezone for the returned Timestamp object.

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32399 POSTS0 COMMENTS
Milvus
95 POSTS0 COMMENTS
Nango Kala
6765 POSTS0 COMMENTS
Nicole Veronica
11917 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11984 POSTS0 COMMENTS
Shaida Kate Naidoo
6889 POSTS0 COMMENTS
Ted Musemwa
7142 POSTS0 COMMENTS
Thapelo Manthata
6837 POSTS0 COMMENTS
Umr Jansen
6840 POSTS0 COMMENTS