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>I would go for a declarative way through a dict, simple to read and easy to apply. You can generate your replace condition dictionary programmatically if the replacement conditions become large or depends on other inputs:</p>

<pre><code>conditions = {1:'term1', 2:'term1', 3:'term1',
              4:'term2', 5:'term2',
              6:'term3', 7:'term3'}

df['term'] = df.replace(conditions)
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