MAI/LabWork01/AnalysSalesCustomers.py

38 lines
1.5 KiB
Python
Raw Permalink Normal View History

2023-09-28 20:48:51 +04:00
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()
2023-10-12 17:46:05 +04:00
minMaxMean_one.columns = minMaxMean_one.columns.droplevel()
2023-09-28 20:48:51 +04:00
minMaxMean_two = table_two.agg({'Store_Sales': ['min', 'max', 'mean']}).round(2).reset_index()
2023-10-12 17:46:05 +04:00
minMaxMean_two.columns = minMaxMean_two.columns.droplevel()
minMaxMean_two = minMaxMean_two.iloc[:, 1:4]
2023-09-28 20:48:51 +04:00
minMaxMean_three = table_three.agg({'Store_Sales': ['min', 'max', 'mean']}).round(2).reset_index()
2023-10-12 17:46:05 +04:00
minMaxMean_three.columns = minMaxMean_three.columns.droplevel()
minMaxMean_three = minMaxMean_three.iloc[:, 1:4]
2023-09-28 20:48:51 +04:00
2023-10-12 17:46:05 +04:00
df1 = pd.DataFrame()
df1['small'] = minMaxMean_one['min']
df1['average'] = minMaxMean_two['min']
df1['big'] = minMaxMean_three['min']
2023-09-28 20:48:51 +04:00
2023-10-12 17:46:05 +04:00
df2 = pd.DataFrame()
df2['small'] = minMaxMean_one['max']
df2['average'] = minMaxMean_two['max']
df2['big'] = minMaxMean_three['max']
2023-09-28 20:48:51 +04:00
2023-10-12 17:46:05 +04:00
df3 = pd.DataFrame()
df3['small'] = minMaxMean_one['mean']
df3['average'] = minMaxMean_two['mean']
df3['big'] = minMaxMean_three['mean']
totalTable = [df1, df2, df3]
2023-09-28 20:48:51 +04:00
return totalTable