📅  最后修改于: 2023-12-03 15:04:22.275000             🧑  作者: Mango
Python | Pandas Timestamp.fromtimestamp
The Timestamp.fromtimestamp()
method in the Pandas library is used to create a Timestamp object from a Unix timestamp (number of seconds since January 1, 1970, at 00:00:00 UTC).
pandas.Timestamp.fromtimestamp(timestamp, tz=None)
timestamp
: A Unix timestamp (float or integer) representing the number of seconds since January 1, 1970, at 00:00:00 UTC.tz
(optional): Timezone to localize the timestamp.The fromtimestamp()
method returns a Pandas Timestamp
object representing the input Unix timestamp.
import pandas as pd
# Create a Timestamp object from a Unix timestamp
timestamp = pd.Timestamp.fromtimestamp(1609459200)
print(timestamp)
Output:
2021-01-01 00:00:00
In the above example, the Unix timestamp 1609459200
corresponds to '2021-01-01 00:00:00'
in human-readable format. The fromtimestamp()
method converts this Unix timestamp into a Pandas Timestamp object.
fromtimestamp()
method preserves them in the returned Timestamp object.tz
argument can be used to localize the timestamp to a specific timezone. If no timezone is provided, the resulting Timestamp object is timezone-naive.For more information, refer to the Pandas documentation on Timestamp.fromtimestamp.