feinmann
feinmann

Reputation: 1122

Pandas: Fill new column by condition row-wise

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()

enter image description here

How can I create a new column which indicates that value is between lower and upper ?

Upvotes: 0

Views: 507

Answers (1)

Nickil Maveli
Nickil Maveli

Reputation: 29719

You can use between for this purpose.

df['new_col'] = df['value'].between(df['lower'], df['upper'])

Upvotes: 2

Related Questions