how to add column by using other column's conditions
<p>I have a dataframe.</p>

<pre><code>df=pd.DataFrame({'month':np.arange(1,8)})
</code></pre>

<p>So,I would like to add column by using 'month' columns</p>

<pre><code>if 'month'=1,2,3   the elements = 'term1'
   'month'=4,5     the elements = 'term2' 
   'month'=6,7     the elements = 'term3'
</code></pre>

<p>I would like to get the result below</p>

<pre><code>      month  term 
0       1    term1
1       2    term1
2       3    term1
3       4    term2
4       5    term2
5       6    term3
6       7    term3
</code></pre>

<p>How can I get this result?
maybe we could get this result easy and simple way....</p>

<p>Use <code>numpy.where</code> and <code>Series.isin()</code> method could be one of the options to do it:</p>

<pre><code>import numpy as np
import pandas as pd
df["term"] = np.where(df.month.isin([1,2,3]), "term1", \
                      np.where(df.month.isin([4,5]), "term2", "term3"))

df
# month  term
#0    1 term1
#1    2 term1
#2    3 term1
#3    4 term2
#4    5 term2
#5    6 term3
#6    7 term3
</code></pre>

python pandas