@@ -564,6 +564,17 @@ def tz(self) -> tzinfo | None:
564
564
-------
565
565
datetime.tzinfo, pytz.tzinfo.BaseTZInfo, dateutil.tz.tz.tzfile, or None
566
566
Returns None when the array is tz-naive.
567
+
568
+ Examples
569
+ --------
570
+ >>> s = pd.Series(["1/1/2020 10:00:00+00:00", "2/1/2020 11:00:00+00:00"])
571
+ >>> s = pd.to_datetime(s)
572
+ >>> s
573
+ 0 2020-01-01 10:00:00+00:00
574
+ 1 2020-02-01 11:00:00+00:00
575
+ dtype: datetime64[ns, UTC]
576
+ >>> s.dt.tz
577
+ datetime.timezone.utc
567
578
"""
568
579
# GH 18595
569
580
return getattr (self .dtype , "tz" , None )
@@ -1312,6 +1323,19 @@ def time(self) -> npt.NDArray[np.object_]:
1312
1323
Returns numpy array of :class:`datetime.time` objects.
1313
1324
1314
1325
The time part of the Timestamps.
1326
+
1327
+ Examples
1328
+ --------
1329
+ >>> s = pd.Series(["1/1/2020 10:00:00+00:00", "2/1/2020 11:00:00+00:00"])
1330
+ >>> s = pd.to_datetime(s)
1331
+ >>> s
1332
+ 0 2020-01-01 10:00:00+00:00
1333
+ 1 2020-02-01 11:00:00+00:00
1334
+ dtype: datetime64[ns, UTC]
1335
+ >>> s.dt.time
1336
+ 0 10:00:00
1337
+ 1 11:00:00
1338
+ dtype: object
1315
1339
"""
1316
1340
# If the Timestamps have a timezone that is not UTC,
1317
1341
# convert them into their i8 representation while
@@ -1326,6 +1350,19 @@ def timetz(self) -> npt.NDArray[np.object_]:
1326
1350
Returns numpy array of :class:`datetime.time` objects with timezones.
1327
1351
1328
1352
The time part of the Timestamps.
1353
+
1354
+ Examples
1355
+ --------
1356
+ >>> s = pd.Series(["1/1/2020 10:00:00+00:00", "2/1/2020 11:00:00+00:00"])
1357
+ >>> s = pd.to_datetime(s)
1358
+ >>> s
1359
+ 0 2020-01-01 10:00:00+00:00
1360
+ 1 2020-02-01 11:00:00+00:00
1361
+ dtype: datetime64[ns, UTC]
1362
+ >>> s.dt.timetz
1363
+ 0 10:00:00+00:00
1364
+ 1 11:00:00+00:00
1365
+ dtype: object
1329
1366
"""
1330
1367
return ints_to_pydatetime (self .asi8 , self .tz , box = "time" , reso = self ._creso )
1331
1368
@@ -1336,6 +1373,19 @@ def date(self) -> npt.NDArray[np.object_]:
1336
1373
1337
1374
Namely, the date part of Timestamps without time and
1338
1375
timezone information.
1376
+
1377
+ Examples
1378
+ --------
1379
+ >>> s = pd.Series(["1/1/2020 10:00:00+00:00", "2/1/2020 11:00:00+00:00"])
1380
+ >>> s = pd.to_datetime(s)
1381
+ >>> s
1382
+ 0 2020-01-01 10:00:00+00:00
1383
+ 1 2020-02-01 11:00:00+00:00
1384
+ dtype: datetime64[ns, UTC]
1385
+ >>> s.dt.date
1386
+ 0 2020-01-01
1387
+ 1 2020-02-01
1388
+ dtype: object
1339
1389
"""
1340
1390
# If the Timestamps have a timezone that is not UTC,
1341
1391
# convert them into their i8 representation while
@@ -1614,6 +1664,19 @@ def isocalendar(self) -> DataFrame:
1614
1664
"doy" ,
1615
1665
"""
1616
1666
The ordinal day of the year.
1667
+
1668
+ Examples
1669
+ --------
1670
+ >>> s = pd.Series(["1/1/2020 10:00:00+00:00", "2/1/2020 11:00:00+00:00"])
1671
+ >>> s = pd.to_datetime(s)
1672
+ >>> s
1673
+ 0 2020-01-01 10:00:00+00:00
1674
+ 1 2020-02-01 11:00:00+00:00
1675
+ dtype: datetime64[ns, UTC]
1676
+ >>> s.dt.dayofyear
1677
+ 0 1
1678
+ 1 32
1679
+ dtype: int32
1617
1680
""" ,
1618
1681
)
1619
1682
dayofyear = day_of_year
@@ -1622,13 +1685,39 @@ def isocalendar(self) -> DataFrame:
1622
1685
"q" ,
1623
1686
"""
1624
1687
The quarter of the date.
1688
+
1689
+ Examples
1690
+ --------
1691
+ >>> s = pd.Series(["1/1/2020 10:00:00+00:00", "4/1/2020 11:00:00+00:00"])
1692
+ >>> s = pd.to_datetime(s)
1693
+ >>> s
1694
+ 0 2020-01-01 10:00:00+00:00
1695
+ 1 2020-04-01 11:00:00+00:00
1696
+ dtype: datetime64[ns, UTC]
1697
+ >>> s.dt.quarter
1698
+ 0 1
1699
+ 1 2
1700
+ dtype: int32
1625
1701
""" ,
1626
1702
)
1627
1703
days_in_month = _field_accessor (
1628
1704
"days_in_month" ,
1629
1705
"dim" ,
1630
1706
"""
1631
1707
The number of days in the month.
1708
+
1709
+ Examples
1710
+ --------
1711
+ >>> s = pd.Series(["1/1/2020 10:00:00+00:00", "2/1/2020 11:00:00+00:00"])
1712
+ >>> s = pd.to_datetime(s)
1713
+ >>> s
1714
+ 0 2020-01-01 10:00:00+00:00
1715
+ 1 2020-02-01 11:00:00+00:00
1716
+ dtype: datetime64[ns, UTC]
1717
+ >>> s.dt.daysinmonth
1718
+ 0 31
1719
+ 1 29
1720
+ dtype: int32
1632
1721
""" ,
1633
1722
)
1634
1723
daysinmonth = days_in_month
0 commit comments