File: if_then.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 (12 lines) | stat: -rw-r--r-- 265 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
The same operation in pandas can be accomplished using
the ``where`` method from ``numpy``.

.. ipython:: python

   tips["bucket"] = np.where(tips["total_bill"] < 10, "low", "high")
   tips

.. ipython:: python
   :suppress:

   tips = tips.drop("bucket", axis=1)