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.
Recommended Posts:
- Python | pandas.map()
- Python | Pandas Index.contains()
- Python | Pandas Series.str.contains()
- Python | Pandas dataframe.sem()
- Python | Pandas dataframe.add()
- Python | Pandas DataFrame.loc[]
- Python | Pandas Index.where
- Python | Pandas Series.str.pad()
- Python | Pandas Period.day
- Python | Pandas Timestamp.tz
- Python | Pandas Dataframe.iat[ ]
- Python | Pandas Dataframe.at[ ]
- Python | Pandas Period.second
- Python | Pandas Series.std()
- Python | Pandas Series.take()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

