通过输入的三位数字,显示前三位和输入内容相同的数据。

问题遇到的现象和发生背景

原先是使用query查询相符的客户代码显示,现在想改变成通过查询前三位的数字,显示前三位和输入的数字相同的数据。

img

用代码块功能插入代码,请勿粘贴截图
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)

运行结果及报错内容

img

我的解答思路和尝试过的方法

使用了切片的方式,没有成功。

我想要达到的结果

通过查询前三位的数字,显示前三位和输入的数字相同的数据

试试模糊查询或者for循环遍历加i[:3]匹配符合条件的