MAI/LabWork01/DataFrameAnalys.py
2023-10-12 17:46:05 +04:00

39 lines
1.5 KiB
Python

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_one.columns = minMaxMean_one.columns.droplevel()
minMaxMean_two = table_two.agg({'Items_Available': ['min', 'max', 'mean']}).round(2).reset_index()
minMaxMean_two.columns = minMaxMean_two.columns.droplevel()
minMaxMean_two = minMaxMean_two.iloc[:, 1:4]
minMaxMean_three = table_three.agg({'Items_Available': ['min', 'max', 'mean']}).round(2).reset_index()
minMaxMean_three.columns = minMaxMean_three.columns.droplevel()
minMaxMean_three = minMaxMean_three.iloc[:, 1:4]
df1 = pd.DataFrame()
df1['small'] = minMaxMean_one['min']
df1['average'] = minMaxMean_two['min']
df1['big'] = minMaxMean_three['min']
df2 = pd.DataFrame()
df2['small'] = minMaxMean_one['max']
df2['average'] = minMaxMean_two['max']
df2['big'] = minMaxMean_three['max']
df3 = pd.DataFrame()
df3['small'] = minMaxMean_one['mean']
df3['average'] = minMaxMean_two['mean']
df3['big'] = minMaxMean_three['mean']
totalTable = [df1, df2, df3]
return totalTable