1 图 |
2 图 |
import pandas as pd
df=pd.read_excel ("数据集 A.xlsx")
cp=["小炒时蔬","红烧牛肉","黄焖鸡","红烧肉","粉蒸肉","梅菜扣肉","糖醋排骨 ","烧圆子","小炒肉","水煮肉片","香菇炒肉","鱼香肉丝","烤鸭","香酥鸭","烧 带鱼","炸小鱼","大锅菜","番茄鸡蛋","麻婆豆腐","凉拌黄瓜"]
cpdic={"小炒时蔬":0,"红烧牛肉":1,"黄焖鸡":2,"红烧肉":3,"粉蒸肉":4,"梅菜扣 肉":5,"糖醋排骨":6,"烧圆子":7,"小炒肉":8,"水煮肉片":9,"香菇炒肉":10,"鱼香 肉丝":11,"烤鸭":12,"香酥鸭":13,"烧带鱼":14,"炸小鱼":15,"大锅菜":16,"番茄 鸡蛋":17,"麻婆豆腐":18,"凉拌黄瓜":19}
a=[]
for i in df.values:
# 列表 a 分别存储订单编号、菜品 id、菜品名称
a.append([i[2],i[4],i[5]])
n,ncp=len(a),len(cp)
num=[0]*ncp
j=0
cpmc=input("请输入菜品:")
key=cpdic[cpmc] # 通过菜品名称获取菜品 id
while j<n:
if j==0 or a[j-1][0]!=a[j][0]:
start=j
if a[j][1]==key:
while a[j][0]==a[start][0]:
if start!=j:
num[ ]+=1
start+=1
if start==n:
break
# 改错
j+=1
for i in range(3): # 输出三个套餐搭配建议
for j in range(ncp-1,i,-1):
if :
num[j-1],num[j]=num[j],num[j-1]
cp[j-1],cp[j]=cp[j],cp[j-1]
print("建议套餐中包含",cpmc,"与",cp[i],",两个菜品关联次数为",num[i])