熊猫:按行条件填写新列

时间:2016-08-31 09:46:59

标签: python pandas

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

如何创建新列,表明value介于lowerupper之间?

1 个答案:

答案 0 :(得分:3)

您可以将between用于此目的。

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