Back to Pandas

If Then

doc/source/getting_started/comparison/includes/if_then.rst

3.1.0.dev0264 B
Original Source

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)