[英]Add Case=False to my code when creating a new variable
I want to add Case=False
to the code below so the NON_COV_RFV
would flag both 'Seizure' and 'seizure' but am getting an error.我想将
Case=False
添加到下面的代码中,以便NON_COV_RFV
会同时标记“癫痫发作”和“癫痫发作”,但会出现错误。 Is it possible to add a case=False?是否可以添加 case=False? I know this can be done in str.contains but there are data in my
REASON_FOR_VISIT
field, for example seizure, fever
, and I would not want to flag that as NON_COV_RFV
.我知道这可以在 str.contains 中完成,但我的
REASON_FOR_VISIT
字段中有数据,例如seizure, fever
,我不想将其标记为NON_COV_RFV
。
I want to avoid having to write another line of code for "seizure".我想避免为“癫痫发作”编写另一行代码。 If it were for just this occurrence it would be fine to add a second line but I have many variables for
REASON_FOR_VISIT
and that is why I would like to figure out if I can plug in a case=False
expression.如果只是为了这种情况,添加第二行就可以了,但我有很多
REASON_FOR_VISIT
变量,这就是为什么我想知道是否可以插入case=False
表达式。
COV_RFV.loc[COV_RFV['REASON_FOR_VISIT'] == 'Seizure', case=False, 'NON_COV_RFV'] = 1
ERROR:错误:
COV_RFV.loc[COV_RFV['REASON_FOR_VISIT'] == 'Seizure', case=False, 'NON_COV_RFV'] = 1
^
SyntaxError: invalid syntax
This is not possible, but you could use this workaround:这是不可能的,但您可以使用以下解决方法:
COV_RFV.loc[COV_RFV['REASON_FOR_VISIT'].str.lower() == 'seizure', 'NON_COV_RFV'] = 1
or或者
COV_RFV.loc[COV_RFV['REASON_FOR_VISIT'].str.match('Seizure', case=False), 'NON_COV_RFV'] = 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.