📜  Python| Pandas Timestamp.fromtimestamp(1)

📅  最后修改于: 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).

Syntax
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.
Return Value

The fromtimestamp() method returns a Pandas Timestamp object representing the input Unix timestamp.

Example
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.

Additional Notes
  • If the Unix timestamp has fractional seconds, the fromtimestamp() method preserves them in the returned Timestamp object.
  • The 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.