MAI/LabWork01/AnalysSales.py
2023-09-28 20:48:51 +04:00

23 lines
1.0 KiB
Python

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