pandas.Timestamp — pandas 3.0.0.dev0+2095.g2e141aaf99 documentation (original) (raw)

class pandas.Timestamp(ts_input=, year=None, month=None, day=None, hour=None, minute=None, second=None, microsecond=None, tzinfo=None, *, nanosecond=None, tz=, unit=None, fold=None)[source]#

Pandas replacement for python datetime.datetime object.

Timestamp is the pandas equivalent of python’s Datetime and is interchangeable with it in most cases. It’s the type used for the entries that make up a DatetimeIndex, and other timeseries oriented data structures in pandas.

Parameters:

ts_inputdatetime-like, str, int, float

Value to be converted to Timestamp.

yearint

Value of year.

monthint

Value of month.

dayint

Value of day.

hourint, optional, default 0

Value of hour.

minuteint, optional, default 0

Value of minute.

secondint, optional, default 0

Value of second.

microsecondint, optional, default 0

Value of microsecond.

tzinfodatetime.tzinfo, optional, default None

Timezone info.

nanosecondint, optional, default 0

Value of nanosecond.

tzstr, zoneinfo.ZoneInfo, pytz.timezone, dateutil.tz.tzfile or None

Time zone for time which Timestamp will have.

unitstr

Unit used for conversion if ts_input is of type int or float. The valid values are ‘W’, ‘D’, ‘h’, ‘m’, ‘s’, ‘ms’, ‘us’, and ‘ns’. For example, ‘s’ means seconds and ‘ms’ means milliseconds.

For float inputs, the result will be stored in nanoseconds, and the unit attribute will be set as 'ns'.

fold{0, 1}, default None, keyword-only

Due to daylight saving time, one wall clock time can occur twice when shifting from summer to winter time; fold describes whether the datetime-like corresponds to the first (0) or the second time (1) the wall clock hits the ambiguous time.

See also

Timedelta

Represents a duration, the difference between two dates or times.

datetime.datetime

Python datetime.datetime object.

Notes

There are essentially three calling conventions for the constructor. The primary form accepts four parameters. They can be passed by position or keyword.

The other two forms mimic the parameters from datetime.datetime. They can be passed by either position or keyword, but not both mixed together.

Examples

Using the primary calling convention:

This converts a datetime-like string

pd.Timestamp('2017-01-01T12') Timestamp('2017-01-01 12:00:00')

This converts a float representing a Unix epoch in units of seconds

pd.Timestamp(1513393355.5, unit='s') Timestamp('2017-12-16 03:02:35.500000')

This converts an int representing a Unix-epoch in units of weeks

pd.Timestamp(1535, unit='W') Timestamp('1999-06-03 00:00:00')

This converts an int representing a Unix-epoch in units of seconds and for a particular timezone

pd.Timestamp(1513393355, unit='s', tz='US/Pacific') Timestamp('2017-12-15 19:02:35-0800', tz='US/Pacific')

Using the other two forms that mimic the API for datetime.datetime:

pd.Timestamp(2017, 1, 1, 12) Timestamp('2017-01-01 12:00:00')

pd.Timestamp(year=2017, month=1, day=1, hour=12) Timestamp('2017-01-01 12:00:00')

Attributes

Methods