Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Pandas · Function

pd.Timestamp

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.

How it works

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.

Syntax

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*)

Parameters

NameTypeDescription
ts_inputdatetime-like, str, int, floatValue to convert; accepts datetime-like input, strings, integers, or floats.
yearint, optionalCalendar year, used by the datetime-style constructor.
monthint, optionalCalendar month, used by the datetime-style constructor.
dayint, optionalCalendar day, used by the datetime-style constructor.
hourint, optionalHour component.
minuteint, optionalMinute component.
secondint, optionalSecond component.
microsecondint, optionalMicrosecond component.
tzinfodatetime.tzinfo, optionalA datetime.tzinfo value for timezone information.
nanosecondint, optionalNanosecond component.
tzstr, pytz.timezone, dateutil.tz.tzfile or NoneTimezone for the resulting timestamp.
unitstrResolution used when numeric input is converted.

Returns

A pandas Timestamp object representing the supplied value or components.

Key points

  • Timestamp provides pandas’ datetime scalar type as a replacement for Python’s datetime.datetime.
  • It behaves much like Python datetime for most interoperability scenarios.
  • Datetime indexes contain 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.
  • The tz parameter assigns timezone information to the resulting timestamp.
  • For numeric input, unit controls the time resolution used during conversion.

Common mistakes

  • Component-based construction follows datetime.datetime conventions, so use the documented positional or keyword form rather than mixing those styles.
  • When converting integer or floating-point input, unit must use one of the supported resolution codes.
  • Do not combine positional and keyword arguments in the datetime-like constructor forms.

Example: Create timestamps from common inputs

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.

When to use it

Parse date-time text

Parse a date-time string into a pandas scalar for comparisons, indexing, or time-series operations.

Interpret epoch values

Convert Unix epoch numbers when their resolution is known.

Attach timezone information

Create timezone-aware timestamps for time-series data spanning explicit zones.

Build from components

Represent individual calendar components with datetime-compatible construction.

Interview questions

QWhat is 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.

QHow does 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.

QWhat constructor conventions does 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.DatetimeIndex
  • datetime.datetime

Source: pandas.Timestamp. Checked 2026-10-15.