1 回答
TA贡献1793条经验 获得超6个赞
s = '9-999'
q = df[df['Column_1']==str(s)]
if len(q):
print(q)
else:
m = df[['Column_2', 'Column_3']].apply(lambda x: x['Column_2'] <= s <= x['Column_3'], axis=1)
print(df[m])
印刷:
School_ID Column_1 Column_2 Column_3
1 School 2 9-999 0.0 0.0
为了s = 8110:
School_ID Column_1 Column_2 Column_3
0 School 1 0 8100.0 8200.0
编辑:为了获得一致的数据类型,您可以将 Column2 和 Column3 转换为浮点数:
s = '8110'
q = df[df['Column_1']==str(s)]
df['Column_2'] = df['Column_2'].astype(float)
df['Column_3'] = df['Column_3'].astype(float)
if len(q):
print(q)
else:
s = float(s)
m = df[['Column_2', 'Column_3']].apply(lambda x: x['Column_2'] <= s <= x['Column_3'], axis=1)
print(df[m])
添加回答
举报