原先是使用query查询相符的客户代码显示,现在想改变成通过查询前三位的数字,显示前三位和输入的数字相同的数据。
def query_info():
df = pd.read_excel('客户代码.xlsx')
# medal_data = pd.DataFrame()
customerCode = request.form.get("customerCode", "")
if customerCode:
medal_data = df.query(f"客户代码 == '{customerCode}'")
# medal_data = df.query(f"客户代码[:3] == @re.sub(r'^.{customerCode}','', @target)")
# medal_data=df.loc[df['客户代码'][:3]=='{customerCode}']
return f"""
<html><body style="text-align:center">
<h1>查询客户代码信息</h1>
<form action="/query" method="post">
客户代码:<input type="text" name="customerCode" value="{customerCode}">
<input type="submit" name="submit" value="查询">
</form>
<center>%s</center>
</body></html>
""" %medal_data.to_html(index=False)
使用了切片的方式,没有成功。
通过查询前三位的数字,显示前三位和输入的数字相同的数据
试试模糊查询或者for循环遍历加i[:3]匹配符合条件的