Conditional Statement to update columns based on range I have a dataframe called clients that has 5000+ rows with the following:

ID   Ordered   Days
1     101565    131
2     202546    122
3     459863    78
4     328453    327
5     458975    -27


I'm trying to create a loop that looks at the numbers of days and replace them with a new columns if it does meet the days critetaria based on the 
following:

Days           NEW_COLUMNS
0-119          0-3 Months
120-209        4-6 Months
210-299        7-9 Months
300+           10+ Months
-280 to -196   Reach out clients
-195 to -104   Send promotion
-103 to -1     Close case
&lt; -280         Plan


I have the following code but hasn't worked so far:

if(days &lt;-280)(NEW_COLUMNS ="plan")
else if (days&gt;-280 &amp;&amp; days &lt;-196)(NEW_COLUMNS=" Reach out clients";)
else if (days&gt;-195 &amp;&amp; days&lt;-104)(NEW_COLUMNS =" Send promotion";)
else if (days&gt;-103 &amp;&amp; days &lt;-1)(NEW_COLUMNS="Close case";)
else if(days&gt; 0 &amp;&amp; days &lt;119)(NEW_COLUMNS="0-3 Months";)
else if(days &gt; 120 &amp;&amp; days &lt;209)(NEW_COLUMNS="4-6 Mos";)
else if(days &gt; 210 &amp;&amp; day s&lt;299)(NEW_COLUMNS="7-9 Mos";)
else if(days &gt; 300)(NEW_COLUMNS="10+ Mos";)


Eventually I want a table that looks like this:

ID   Ordered   Days    New_Columns
1     101565    131     4-6 Months 
2     202546    122     4-6 Months
3     459863    78      0-3 Months 
4     328453    327     10+ Months
5     458975    -27     Close case
One elegant way to solve this is by using numpy.select. This function takes a list of conditions and a list of choices and then pick the choice where the first condition is true.

An advantage is that since the conditions are checked in order, only one side of the condition for the day value needs to be checked.

Assuming the input dataframe is called df:

import numpy as np
import pandas as pd

conditions = [
    df['Days'] &lt; -280,
    df['Days'] &lt; -195,
    df['Days'] &lt; -103,
    df['Days'] &lt; 0,
    df['Days'] &lt; 120,
    df['Days'] &lt; 210,
    df['Days'] &lt; 300,
    True
]

outputs = [
    "Plan", "Reach out clients", "Send promotion", "Close case",
    "0-3 Months", "4-6 Months", "7-9 Months", "10+ Months"
]

df['New_Columns'] = np.select(conditions, outputs)


Result:

    ID  Ordered  Days New_Columns
0   1   101565   131  4-6 Months
1   2   202546   122  4-6 Months
2   3   459863    78  0-3 Months
3   4   328453   327  10+ Months
4   5   458975   -27  Close case