python - IF条件语句在使用Python时不起作用
问题描述
我正在尝试在 2 个条件下执行脚本,如果两个条件都满足,则只能执行进一步的代码。
输入数据: Sheet1
Name Contact_number id_number accuracy
Eric 9786543628 AZ256hy 90
Jack 9786543628 AZ98kds 85
Tom 9784533930 AZ256hc 80
Alan 9778934593 AZ256py 70
表 2
Name Contact_number id_number
Eric 9786543628 AZ256hy
Jack 9786543628 AZ98kds
Tom 9784533930 AZ256hc
David 9778984893 JH657lv
预期输出:
Name Contact_number id_number
Eric 9786543628 AZ256hy
Jack 9786543628 AZ98kds
我一直在使用的代码:
df = pd.read_excel(open(r'input.xlsx', 'rb'), sheet_name='sheet1')
df2 = pd.read_excel(open(r'input.xlsx', 'rb'), sheet_name='sheet2')
if df['id_number'] = df2['id_number'] and df['accuracy'] =>85:
df['Name'][index] = df2['Name']
df['Contact_number'][index] = df2['Contact_number']
但是在使用此条件时,if 语句不适用于AND条件。有什么建议吗?
解决方案
编辑:我对条件进行了更改。这应该工作
df = pd.read_excel(open(r'input.xlsx', 'rb'), sheet_name='sheet1')
df2 = pd.read_excel(open(r'input.xlsx', 'rb'), sheet_name='sheet2')
df.loc[(df['id_number'] == df2['id_number']) & (df['accuracy']>= 85),['Name','Contact_number', 'id_number']]
推荐阅读
- swift - 为什么不调用 locationManager (:didUpdateLocations)
- r - 如何更改 R 中直方图图例中的字体类型?
- tensorflow - x.shape 和 tf.shape(x) 之间的可变大小不匹配?
- c# - C#:序列不包含在实现 parallel.foreach 循环后引发的元素问题
- json - 基于json数组从akka http响应中获取实体的序列
- javascript - 创建条件 if/else 语句以显示最终测验分数结果
- javascript - 填写完所有 Google 输入字段后提示“嗨”
- c# - 搜索功能未按预期工作
- python - IRC 消息随机不从机器人发送
- python - 如何比蛮力更好地从字典中构建 Plinko 单词板?