File: time_date.rst

package info (click to toggle)
pandas 2.2.3%2Bdfsg-9
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 66,784 kB
  • sloc: python: 422,228; ansic: 9,190; sh: 270; xml: 102; makefile: 83
file content (22 lines) | stat: -rw-r--r-- 644 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
.. ipython:: python

   tips["date1"] = pd.Timestamp("2013-01-15")
   tips["date2"] = pd.Timestamp("2015-02-15")
   tips["date1_year"] = tips["date1"].dt.year
   tips["date2_month"] = tips["date2"].dt.month
   tips["date1_next"] = tips["date1"] + pd.offsets.MonthBegin()
   tips["months_between"] = tips["date2"].dt.to_period("M") - tips[
       "date1"
   ].dt.to_period("M")

   tips[
       ["date1", "date2", "date1_year", "date2_month", "date1_next", "months_between"]
   ]

.. ipython:: python
   :suppress:

   tips = tips.drop(
       ["date1", "date2", "date1_year", "date2_month", "date1_next", "months_between"],
       axis=1,
   )