我想要做以下(伪代码):国旗上其他列条件
for each row of my dataframe;
if the value of the cell "date" is between the values of the cells "begin" and "end", then write "1" in the cell "flag", 0 otherwise
我试过如下:
df['flag'] = 1
df['flag'] = df['flag'].apply(lambda x:x if (df['begin'] < df['date'] and df['date'] < df['end']) else 0)
# (I'm coming from R...)
我也得到:
The truth value of a Series is ambiguous
我得到了Python告诉我的情况,即在这种情况下,它并不比较每行中单元格的内容,而是比较整列。
我怎样才能得到我想要的? (该解决方案不必遵循相同的方法,我是Python的新手,在这里学习)
谢谢。
'的foreach DF中dataframe:\ n if df ['begin']
'SyntaxError:invalid syntax'(指向第一个'df'部分) –
'for'而不是'foreach'当然...对不起那 –