Pandas 基于其他列中的多个条件更新列字符串值
如果cust_用户名为“BOB”,则希望将cust_cdr_display_name字段中的任何零值更新为“BOC”Pandas 基于其他列中的多个条件更新列字符串值,pandas,dataframe,criteria,Pandas,Dataframe,Criteria,如果cust_用户名为“BOB”,则希望将cust_cdr_display_name字段中的任何零值更新为“BOC” originating_system_id ticker cust_cdr_display_name cust_username BBT T 2 3/4 02/15/28 0 BOB BBT T 2 1/4 11/15/27
originating_system_id ticker cust_cdr_display_name cust_username
BBT T 2 3/4 02/15/28 0 BOB
BBT T 2 1/4 11/15/27 0 BOB
originating_system_id ticker cust_cdr_display_name cust_username
BBT T 2 3/4 02/15/28 BOC BOB
BBT T 2 1/4 11/15/27 BOC BOB
代码:
我得到了一个错误:
cannot copy sequence with size 40 to array axis with dimension 2
如何使掩码条件接受多个条件?您已接近,需要在链接布尔掩码中省略
df[]
:
mask = (
df['cust_cdr_display_name'] == 0
)
&
(
df['cust_username'] == 'BOB'
)
是熊猫,不是r
mask = (
df['cust_cdr_display_name'] == 0
)
&
(
df['cust_username'] == 'BOB'
)