[英]Multiple Conditions in 1 Variable
我想將多個條件放入一個變量中,以便確定要插入到“EmptyCol”列中的值。 請參閱下文。 注意:這適用於一種條件,但我相信我錯過了具有多種條件的東西
Condition = ((df['status']=='Live') and
(df['name'].str.startswith('A') and
(df['true']==1))
df.loc[Condition, 'EmptyCol'] = 'True'
使用“&”代替“and”
Condition = ((df['status']=='Live') &
(df['name'].str.startswith('A') &
(df['true']==1))
我也建議使用 df.at
有時我在 df.loc 上遇到了一些麻煩!
Condition = ((df['status']=='Live') &
(df['name'].str.startswith('A') &
(df['true']==1))
def ChangeValueFunc(Record):
df.at[Record['index'],'EmptyCol'] = 'True'
df_2.loc[Condition ,:].reset_index().apply(lambda x:ChangeValueFunc(x) , axis = 1)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.