相关疑难解决方法(0)

Python中的波形符运算符

Python中代字号运算符的用法是什么?

我能想到的一件事是在字符串或列表的两边做一些事情,比如检查字符串是否是回文符号:

def is_palindromic(s):
    return all(s[i] == s[~i] for i in range(len(s) / 2)) 
Run Code Online (Sandbox Code Playgroud)

还有其他好用吗?

python operators

181
推荐指数
5
解决办法
8万
查看次数

根据条件拆分数据框

我试图将我的数据帧分成两个medical_plan_id.如果它是空的,进入df1.如果不是空的话df2.

df1 = df_with_medicalplanid[df_with_medicalplanid['medical_plan_id'] == ""]
df2 = df_with_medicalplanid[df_with_medicalplanid['medical_plan_id'] is not ""]
Run Code Online (Sandbox Code Playgroud)

下面的代码有效,但如果没有空字段,我的代码就会提升TypeError("invalid type comparison").

df1 = df_with_medicalplanid[df_with_medicalplanid['medical_plan_id'] == ""]
Run Code Online (Sandbox Code Playgroud)

如何处理这种情况?

我的df_with_medicalplanid如下所示:

wellthie_issuer_identifier       ...       medical_plan_id
0                   UHC99806       ...                  None
1                   UHC99806       ...                  None
Run Code Online (Sandbox Code Playgroud)

python pandas

4
推荐指数
1
解决办法
160
查看次数

标签 统计

python ×2

operators ×1

pandas ×1