Parse date-time text
Parse a date-time string into a pandas scalar for comparisons, indexing, or time-series operations.
Pandas · Function
pandas.Timestamp is pandas’ scalar datetime type and a replacement for Python’s datetime.datetime. Construct it from datetime-like values, strings, numeric epoch values, or individual date-time components.
Timestamp constructs a pandas timestamp from datetime-like input, text, or numeric epoch values. It can also be built with calendar components and optional timezone, unit, nanosecond, and fold settings; pandas uses it for entries in DatetimeIndex and other time-series structures.
class pandas.Timestamp(*ts_input=<object object>*, *year=None*, *month=None*, *day=None*, *hour=None*, *minute=None*, *second=None*, *microsecond=None*, *tzinfo=None*, ***, *nanosecond=None*, *tz=None*, *unit=None*, *fold=None*)| Name | Type | Description |
|---|---|---|
ts_input | datetime-like, str, int, float | Value to convert; accepts datetime-like input, strings, integers, or floats. |
year | int, optional | Calendar year, used by the datetime-style constructor. |
month | int, optional | Calendar month, used by the datetime-style constructor. |
day | int, optional | Calendar day, used by the datetime-style constructor. |
hour | int, optional | Hour component. |
minute | int, optional | Minute component. |
second | int, optional | Second component. |
microsecond | int, optional | Microsecond component. |
tzinfo | datetime.tzinfo, optional | A datetime.tzinfo value for timezone information. |
nanosecond | int, optional | Nanosecond component. |
tz | str, pytz.timezone, dateutil.tz.tzfile or None | Timezone for the resulting timestamp. |
unit | str | Resolution used when numeric input is converted. |
A pandas Timestamp object representing the supplied value or components.
Timestamp provides pandas’ datetime scalar type as a replacement for Python’s datetime.datetime.Timestamp values, making this type central to pandas time-series data.ts_input accepts a datetime-like object, string, integer, or float and converts it into a timestamp.tz parameter assigns timezone information to the resulting timestamp.unit controls the time resolution used during conversion.unit must use one of the supported resolution codes.import pandas as pd
ts = pd.Timestamp("2017-01-01T12")
epoch_seconds = pd.Timestamp(1513393355.5, unit="s")
print(ts)
print(epoch_seconds)Creates timestamps from an ISO-like string and from a Unix epoch value expressed in seconds.
Parse a date-time string into a pandas scalar for comparisons, indexing, or time-series operations.
Convert Unix epoch numbers when their resolution is known.
Create timezone-aware timestamps for time-series data spanning explicit zones.
Represent individual calendar components with datetime-compatible construction.
pandas.Timestamp used for?Timestamp is pandas’ replacement for Python’s datetime.datetime and is generally interchangeable with it. It is also the element type used by DatetimeIndex and other time-series-oriented pandas structures.
Follow-up: Why is this useful in a DataFrame? A consistent timestamp type enables pandas time-series indexing and datetime-aware operations across columns and indexes.
Timestamp interpret numeric input?The primary constructor accepts a datetime-like value, string, integer, or float through ts_input. Numeric values can be interpreted with unit, whose supported values include days, hours, minutes, seconds, milliseconds, microseconds, and nanoseconds.
Follow-up: What does Timestamp(1513393355.5, unit='s') represent? It interprets the number as seconds from the Unix epoch, including its fractional part.
Timestamp provide?The constructor supports three calling conventions. The primary form accepts four parameters, while the other two mirror datetime.datetime; arguments may be positional or keyword arguments, but positional and keyword styles must not be mixed in those forms.
Follow-up: How would you represent timezone information? Supply tz for the timestamp timezone, or use tzinfo in the datetime-style form as documented.
pandas.DatetimeIndexdatetime.datetime