Pandas: Fill new column by condition row-wise
<pre><code>import pandas as pd
import numpy as np

df = pd.DataFrame([np.random.rand(100),100*[0.1],100*[0.3]]).T
df.columns = ["value","lower","upper"]

df.head()
</code></pre>

<p><a href="http://i.stack.imgur.com/1J2Gm.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/1J2Gm.jpg" alt="enter image description here"></a></p>

<p>How can I create a new column which indicates that <code>value</code> is between <code>lower</code> and <code>upper</code> ?</p>

<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.between.html" rel="nofollow"><code>between</code></a> for this purpose.</p>

<pre><code>df['new_col'] = df['value'].between(df['lower'], df['upper'])
</code></pre>

python pandas