nowe dane zapisywane do excel

This commit is contained in:
Michał Szuszert 2022-05-12 17:06:27 +02:00
parent b9d5766c21
commit aff02f187f
3 changed files with 48 additions and 1 deletions

BIN
data.xlsx

Binary file not shown.

Binary file not shown.

View File

@ -9,6 +9,7 @@ import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
import json
import openpyxl
pygame.init()
@ -484,8 +485,54 @@ def choose_pizza(prefernce):
clf = DecisionTreeClassifier(random_state=400)
clf = clf.fit(x_train, y_train)
ans = clf.predict([prefernce])
append_choice(ans, prefernce, d, df)
return ans
def append_df_to_excel(df, excel_path):
df_excel = pd.read_excel(excel_path)
result = pd.concat([df_excel, df], ignore_index=True)
result.to_excel(excel_path, index=False)
def append_choice(ans, pre, d, df):
new_row = pre
new_row.append(list(d.keys())[list(d.values()).index(int(ans))])
if new_row[3] == 30:
new_row[3] = 'low'
if new_row[3] == 50:
new_row[3] = 'high'
if new_row[4] == 0:
new_row[4] = 'none'
if new_row[4] == 1:
new_row[4] = 'tomato'
if new_row[4] == 2:
new_row[4] = 'feta'
if new_row[4] == 3:
new_row[4] = 'olives'
if new_row[5] == 0:
new_row[5] = 'none'
if new_row[5] == 1:
new_row[5] = 'salami'
if new_row[5] == 2:
new_row[5] = 'mushrooms'
if new_row[5] == 3:
new_row[5] = 'pineapple'
if new_row[5] == 4:
new_row[5] = 'shrimps'
if new_row[5] == 5:
new_row[5] = 'sausage'
data = {"budget": new_row[0], "spiciness": new_row[1], "vege": new_row[2], "level of hunger": new_row[3],
"allergy": new_row[4], "favorite ingridient": new_row[5], "drink in": 1, "pizza": new_row[7]}
n_df = pd.DataFrame(data, index=[len(df) + 1])
append_df_to_excel(n_df, "restaurant.xlsx")
return clf.predict([prefernce])
def get_pizza(number):
with open("dishes.json") as f: