Lab work 2.

This commit is contained in:
ElEgEv 2023-09-28 20:48:51 +04:00
parent 55e6165fa0
commit 671161347e
7 changed files with 156 additions and 10 deletions

View File

@ -0,0 +1,23 @@
import pandas
import pandas as pd
def analysCustomersDataFrame(df: pandas.DataFrame):
df['Size'] = df['Store_Area'].apply(lambda x: 'Small' if x <= 1100 else ('Average' if 1100 < x <= 1800 else 'Big'))
table_one = df.query("Size == 'Small'").groupby('Size')
table_two = df.query("Size == 'Average'").groupby('Size')
table_three = df.query("Size == 'Big'").groupby('Size')
minMaxMean_one = table_one.agg({'Daily_Customer_Count': ['min', 'max', 'mean']}).round(2).reset_index()
minMaxMean_two = table_two.agg({'Daily_Customer_Count': ['min', 'max', 'mean']}).round(2).reset_index()
minMaxMean_three = table_three.agg({'Daily_Customer_Count': ['min', 'max', 'mean']}).round(2).reset_index()
totalTable = pd.merge(minMaxMean_one, minMaxMean_two, left_index=True, right_index=True)
totalTable = pd.merge(totalTable, minMaxMean_three, left_index=True, right_index=True)
# for data in roundedListShops.items():
# roundedListShops.loc[data[0], 'Store_Area'] = (data[1].astype("Int64")/100)*100
return totalTable

23
LabWork01/AnalysSales.py Normal file
View File

@ -0,0 +1,23 @@
import pandas
import pandas as pd
def analysSalesDataFrame(df: pandas.DataFrame):
df['Size'] = df['Store_Area'].apply(lambda x: 'Small' if x <= 1100 else ('Average' if 1100 < x <= 1800 else 'Big'))
table_one = df.query("Size == 'Small'").groupby('Size')
table_two = df.query("Size == 'Average'").groupby('Size')
table_three = df.query("Size == 'Big'").groupby('Size')
minMaxMean_one = table_one.agg({'Store_Sales': ['min', 'max', 'mean']}).round(2).reset_index()
minMaxMean_two = table_two.agg({'Store_Sales': ['min', 'max', 'mean']}).round(2).reset_index()
minMaxMean_three = table_three.agg({'Store_Sales': ['min', 'max', 'mean']}).round(2).reset_index()
totalTable = pd.merge(minMaxMean_one, minMaxMean_two, left_index=True, right_index=True)
totalTable = pd.merge(totalTable, minMaxMean_three, left_index=True, right_index=True)
# for data in roundedListShops.items():
# roundedListShops.loc[data[0], 'Store_Area'] = (data[1].astype("Int64")/100)*100
return totalTable

View File

@ -0,0 +1,23 @@
import pandas
import pandas as pd
def analysSalesCustomersDataFrame(df: pandas.DataFrame):
df['SaleCustomer'] = df['Daily_Customer_Count'].apply(lambda x: 'Small' if x <= 200 else ('Average' if 200 < x <= 800 else 'Big'))
table_one = df.query("SaleCustomer == 'Small'").groupby('SaleCustomer')
table_two = df.query("SaleCustomer == 'Average'").groupby('SaleCustomer')
table_three = df.query("SaleCustomer == 'Big'").groupby('SaleCustomer')
minMaxMean_one = table_one.agg({'Store_Sales': ['min', 'max', 'mean']}).round(2).reset_index()
minMaxMean_two = table_two.agg({'Store_Sales': ['min', 'max', 'mean']}).round(2).reset_index()
minMaxMean_three = table_three.agg({'Store_Sales': ['min', 'max', 'mean']}).round(2).reset_index()
totalTable = pd.merge(minMaxMean_one, minMaxMean_two, left_index=True, right_index=True)
totalTable = pd.merge(totalTable, minMaxMean_three, left_index=True, right_index=True)
# for data in roundedListShops.items():
# roundedListShops.loc[data[0], 'Store_Area'] = (data[1].astype("Int64")/100)*100
return totalTable

View File

@ -0,0 +1,25 @@
import pandas
import pandas as pd
#или как analysDataFrame(df)->pandas.DataFrame:
def analysItemsDataFrame(df: pandas.DataFrame):
df['Size'] = df['Store_Area'].apply(lambda x: 'Small' if x <= 1100 else ('Average' if 1100 < x <= 1800 else 'Big'))
table_one = df.query("Size == 'Small'").groupby('Size')
table_two = df.query("Size == 'Average'").groupby('Size')
table_three = df.query("Size == 'Big'").groupby('Size')
minMaxMean_one = table_one.agg({'Items_Available': ['min', 'max', 'mean']}).round(2).reset_index()
minMaxMean_two = table_two.agg({'Items_Available': ['min', 'max', 'mean']}).round(2).reset_index()
minMaxMean_three = table_three.agg({'Items_Available': ['min', 'max', 'mean']}).round(2).reset_index()
totalTable = pd.merge(minMaxMean_one, minMaxMean_two, left_index=True, right_index=True)
totalTable = pd.merge(totalTable, minMaxMean_three, left_index=True, right_index=True)
# for data in roundedListShops.items():
# roundedListShops.loc[data[0], 'Store_Area'] = (data[1].astype("Int64")/100)*100
return totalTable

View File

@ -1,7 +1,4 @@
import csv
import numpy as np
import pandas as pd
from LabWork01.Shop import Shop
def createDataFrame():
df = pd.read_csv('../res/Stores.csv')

View File

@ -1,4 +1,9 @@
from flask import Flask, redirect, url_for, request, render_template
from LabWork01.AnalysCustomers import analysCustomersDataFrame
from LabWork01.AnalysSales import analysSalesDataFrame
from LabWork01.AnalysSalesCustomers import analysSalesCustomersDataFrame
from LabWork01.DataFrameAnalys import analysItemsDataFrame
from LabWork01.FuncLoad import createDataFrame
app = Flask(__name__)
@ -14,7 +19,7 @@ countNull = listShops.isnull().sum()
@app.route("/")
def home():
return render_template('main_page.html', context=[], listTypes=listTypes, countNull=countNull, firstRow=1, secondRow=4, firstColumn=1, secondColumn=4)
return render_template('main_page.html', context=[], tableAnalys=[], titles=[''], listTypes=listTypes, countNull=countNull, firstRow=1, secondRow=4, firstColumn=1, secondColumn=4)
@app.route("/showDiapason", methods=['GET','POST'])
def numtext():
@ -61,17 +66,23 @@ def numtext():
#функция для проведения анализа данных
@app.route("/analysis", methods=['GET', 'POST'])
def analysis():
firstAnalys = analysItemsDataFrame(listShops)
roundedListShops = listShops
secondAnalys = analysCustomersDataFrame(listShops)
for data in roundedListShops.items():
roundedListShops.loc[data[0], 'Store_Area'] = (data[1].astype("Int64")/100)*100
thirdAnalys = analysSalesDataFrame(listShops)
#groupingByArea = listShops.groupby(['Store_Area']/100*100).agg({'Items_Available': ['mean']})
fourthAnalys = analysSalesCustomersDataFrame(listShops)
print(roundedListShops)
print(firstAnalys)
return home()
return render_template('main_page.html', context=[], tableAnalysOne=[firstAnalys.to_html()],
tableAnalysTwo=[secondAnalys.to_html()],
tableAnalysThree=[thirdAnalys.to_html()],
tableAnalysFour=[fourthAnalys.to_html()],
titles=[''],
listTypes=listTypes, countNull=countNull, firstRow=1,
secondRow=4, firstColumn=1, secondColumn=4)
if __name__=="__main__":
app.run(debug=True)

View File

@ -52,5 +52,49 @@
{% endfor %}
</table>
</div>
<div>
<h3>
Результаты первого анализа
</h3>
<h1>
{% for table in tableAnalysOne %}
<h2>{{ titles[loop.index] }}</h2>
{{ table|safe }}
{% endfor %}
</h1>
</div>
<div>
<h3>
Результаты второго анализа
</h3>
<h1>
{% for table in tableAnalysTwo %}
<h2>{{ titles[loop.index] }}</h2>
{{ table|safe }}
{% endfor %}
</h1>
</div>
<div>
<h3>
Результаты третьего анализа
</h3>
<h1>
{% for table in tableAnalysThree %}
<h2>{{ titles[loop.index] }}</h2>
{{ table|safe }}
{% endfor %}
</h1>
</div>
<div>
<h3>
Результаты четвёртого анализа
</h3>
<h1>
{% for table in tableAnalysFour %}
<h2>{{ titles[loop.index] }}</h2>
{{ table|safe }}
{% endfor %}
</h1>
</div>
</body>
</html>