File: time_date.rst

package info (click to toggle)
pandas 1.5.3%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 56,516 kB
  • sloc: python: 382,477; ansic: 8,695; sh: 119; xml: 102; makefile: 97
file content (22 lines) | stat: -rw-r--r-- 644 bytes parent folder | download | duplicates (3)
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,
   )