Skip to content

Commit f8c5d5d

Browse files
committed
Enhanced the documentation and added examples in ts offsets Week class
1 parent 8b5dfa2 commit f8c5d5d

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

pandas/_libs/tslibs/offsets.pyx

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,13 +2490,36 @@ cdef class SemiMonthBegin(SemiMonthOffset):
24902490

24912491
cdef class Week(SingleConstructorOffset):
24922492
"""
2493-
Weekly offset.
2493+
Weekly offset.
24942494
2495-
Parameters
2496-
----------
2497-
weekday : int or None, default None
2498-
Always generate specific day of week. 0 for Monday.
2499-
"""
2495+
Parameters
2496+
----------
2497+
weekday : int or None, default None
2498+
Always generate specific day of week. 0 for Monday and 6 for Sunday.
2499+
2500+
Examples
2501+
---------
2502+
## Below examples explain the usage of this object.
2503+
## Importing modules
2504+
import pandas as pd
2505+
2506+
date_format = "%Y-%m-%d"
2507+
date_object = pd.to_datetime("2023-01-13",format = date_format)
2508+
print(date_object)
2509+
## 2023-01-13 00:00:00
2510+
2511+
date_plus_one_week = date_object + pd.tseries.offsets.Week(1)
2512+
print(date_plus_one_week)
2513+
#2023-01-20 00:00:00
2514+
2515+
date_next_Monday = date_object + pd.tseries.offsets.Week(weekday=0)
2516+
print(date_next_Monday)
2517+
#2023-01-16 00:00:00
2518+
2519+
date_next_Sunday = date_object + pd.tseries.offsets.Week(weekday=6)
2520+
print(date_next_Sunday)
2521+
#2023-01-15 00:00:00
2522+
"""
25002523

25012524
_inc = timedelta(weeks=1)
25022525
_prefix = "W"

0 commit comments

Comments
 (0)