Чё-то сделал.

This commit is contained in:
ElEgEv 2023-11-22 23:40:21 +04:00
parent 9b642825c5
commit 4356e23d3b
2 changed files with 18 additions and 10 deletions

View File

@ -4,17 +4,19 @@ def covertorDataFrame():
df = pd.read_csv("../../res/Stores.csv") df = pd.read_csv("../../res/Stores.csv")
countMainRows = 25 # кол-во строчек для считывания
countMainRows = 35
newDf = df.head(countMainRows) # получаем указанное кол-во строчек
mainDF = df.head(countMainRows)
newDf['TextStoreArea'] = df['Store_Area'].apply( mainDF['TextStoreArea'] = mainDF['Store_Area'].apply(
lambda x: 'Small_Area' if x <= 1100 else ('Average_Area' if 1100 < x <= 1700 else 'Big_Area')) lambda x: 'Small_Area' if x <= 1100 else ('Average_Area' if 1100 < x <= 1700 else 'Big_Area'))
newDf['TextStoreSales'] = df['Store_Sales'].apply( mainDF['TextStoreSales'] = mainDF['Store_Sales'].apply(
lambda x: 'Small_Sales' if x <= 50000 else ('Average_Sales' if 50000 < x <= 80000 else 'Big_Sales')) lambda x: 'Small_Sales' if x <= 50000 else ('Average_Sales' if 50000 < x <= 80000 else 'Big_Sales'))
newDf['TextDailyCustomerCount'] = df['Daily_Customer_Count'].apply( mainDF['TextDailyCustomerCount'] = mainDF['Daily_Customer_Count'].apply(
lambda x: 'Small_Customer' if x <= 400 else ('Average_Customer' if 400 < x <= 900 else 'Big_Customer')) lambda x: 'Small_Customer' if x <= 400 else ('Average_Customer' if 400 < x <= 900 else 'Big_Customer'))
# using dictionary to convert specific columns # using dictionary to convert specific columns
@ -25,11 +27,18 @@ def covertorDataFrame():
'Store_Sales': str 'Store_Sales': str
} }
newDf = newDf.astype(convert_dict) mainDF = mainDF.astype(convert_dict)
print(newDf[['TextStoreSales', 'TextStoreSales', 'TextStoreArea']]) # генеральная выборка
newDfGeneral = mainDF.iloc[0:25]
return newDf[['TextDailyCustomerCount', 'TextStoreArea', 'TextStoreSales']] # выборка для проверки
newDfSupport = mainDF.iloc[25:35]
print(newDfSupport[['TextStoreSales', 'TextStoreSales', 'TextStoreArea']])
return [newDfGeneral[['TextDailyCustomerCount', 'TextStoreArea', 'TextStoreSales']],
newDfSupport[['TextDailyCustomerCount', 'TextStoreArea', 'TextStoreSales']]]
# [['Store_Area', 'Store_Sales', 'Daily_Customer_Count', 'TextStoreArea']] # [['Store_Area', 'Store_Sales', 'Daily_Customer_Count', 'TextStoreArea']]

View File

@ -2,7 +2,6 @@ import math
import pandas as pd import pandas as pd
from functools import reduce from functools import reduce
from LabWork01.FuncLoad import createDataFrame
from LabWork01.LabWork6.ConvertorDataFrame import covertorDataFrame from LabWork01.LabWork6.ConvertorDataFrame import covertorDataFrame
# Дата сет # Дата сет
@ -19,7 +18,7 @@ from LabWork01.LabWork6.ConvertorDataFrame import covertorDataFrame
# df0 = pd.DataFrame(data) # df0 = pd.DataFrame(data)
# df0.columns = ["цвет", "форма", "результат"] # df0.columns = ["цвет", "форма", "результат"]
df0 = covertorDataFrame() df0 = covertorDataFrame()[0]
# Лямбда-выражение для распределения значений, аргумент - pandas.Series, # Лямбда-выражение для распределения значений, аргумент - pandas.Series,
# возвращаемое значение - массив с количеством каждого из значений # возвращаемое значение - массив с количеством каждого из значений