Added automizing for datasets
This commit is contained in:
parent
90b819d1a3
commit
f6f24b3ac3
BIN
requirements.txt
BIN
requirements.txt
Binary file not shown.
@ -144,5 +144,5 @@ if __name__ == "__main__":
|
|||||||
url = 'https://www.citilink.ru/catalog/televizory/?ref=mainpage'
|
url = 'https://www.citilink.ru/catalog/televizory/?ref=mainpage'
|
||||||
tvs = scrape_all_pages(url, max_pages=8)
|
tvs = scrape_all_pages(url, max_pages=8)
|
||||||
ignore_fields = ["Работает с"]
|
ignore_fields = ["Работает с"]
|
||||||
save_to_csv(tvs, 'tv.csv', ignore_fields)
|
save_to_csv(tvs, 'datasets/tv.csv', ignore_fields)
|
||||||
print(f"Данные сохранены в файл 'tv.csv'.")
|
print(f"Данные сохранены в файл 'tv.csv'.")
|
||||||
|
@ -119,5 +119,5 @@ if __name__ == "__main__":
|
|||||||
url = 'https://www.citilink.ru/catalog/noutbuki/?ref=mainpage'
|
url = 'https://www.citilink.ru/catalog/noutbuki/?ref=mainpage'
|
||||||
laptops = scrape_all_pages(url, max_pages=20)
|
laptops = scrape_all_pages(url, max_pages=20)
|
||||||
ignore_fields = ["Технология Intel", "Комплектация", "Клавиатура"]
|
ignore_fields = ["Технология Intel", "Комплектация", "Клавиатура"]
|
||||||
save_to_csv(laptops, 'laptops.csv', ignore_fields)
|
save_to_csv(laptops, 'datasets/laptops.csv', ignore_fields)
|
||||||
print(f"Данные сохранены в файл 'laptops.csv'.")
|
print(f"Данные сохранены в файл 'laptops.csv'.")
|
@ -1,3 +1,5 @@
|
|||||||
|
import subprocess
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from sklearn.model_selection import train_test_split, GridSearchCV
|
from sklearn.model_selection import train_test_split, GridSearchCV
|
||||||
from sklearn.ensemble import RandomForestRegressor
|
from sklearn.ensemble import RandomForestRegressor
|
||||||
@ -9,8 +11,24 @@ import numpy as np
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
# Шаг 1: Загрузка данных
|
# Шаг 1: Поиск датасета
|
||||||
df = pd.read_csv('datasets/laptops.csv')
|
# Путь к датасету
|
||||||
|
dataset_path = 'datasets/laptops.csv'
|
||||||
|
# Абсолютный путь к скрипту для создания датасета
|
||||||
|
scraping_script_path = os.path.join(os.getcwd(), 'scraping', 'scrappingLaptop.py')
|
||||||
|
|
||||||
|
# Проверяем, существует ли файл
|
||||||
|
if not os.path.exists(dataset_path):
|
||||||
|
print(f"Файл {dataset_path} не найден. Запускаем скрипт для его создания...")
|
||||||
|
if os.path.exists(scraping_script_path):
|
||||||
|
# Запускаем скрипт для создания датасета
|
||||||
|
subprocess.run(['python', scraping_script_path], check=True)
|
||||||
|
else:
|
||||||
|
print(f"Скрипт {scraping_script_path} не найден.")
|
||||||
|
raise FileNotFoundError(f"Не удалось найти скрипт для создания датасета: {scraping_script_path}")
|
||||||
|
|
||||||
|
# Теперь, когда файл есть, можно продолжить выполнение скрипта
|
||||||
|
df = pd.read_csv(dataset_path)
|
||||||
|
|
||||||
# Шаг 2: Проверка и очистка имен столбцов
|
# Шаг 2: Проверка и очистка имен столбцов
|
||||||
df.columns = df.columns.str.strip().str.lower()
|
df.columns = df.columns.str.strip().str.lower()
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import subprocess
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from sklearn.model_selection import train_test_split, GridSearchCV
|
from sklearn.model_selection import train_test_split, GridSearchCV
|
||||||
from sklearn.ensemble import RandomForestRegressor
|
from sklearn.ensemble import RandomForestRegressor
|
||||||
@ -9,8 +11,23 @@ import numpy as np
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
# Загрузка данных
|
# Путь к датасету
|
||||||
df = pd.read_csv('datasets/tv.csv')
|
dataset_path = 'datasets/tvs.csv'
|
||||||
|
# Абсолютный путь к скрипту для создания датасета
|
||||||
|
scraping_script_path = os.path.join(os.getcwd(), 'scraping', 'scrapingMain.py')
|
||||||
|
|
||||||
|
# Проверяем, существует ли файл
|
||||||
|
if not os.path.exists(dataset_path):
|
||||||
|
print(f"Файл {dataset_path} не найден. Запускаем скрипт для его создания...")
|
||||||
|
if os.path.exists(scraping_script_path):
|
||||||
|
# Запускаем скрипт для создания датасета
|
||||||
|
subprocess.run(['python', scraping_script_path], check=True)
|
||||||
|
else:
|
||||||
|
print(f"Скрипт {scraping_script_path} не найден.")
|
||||||
|
raise FileNotFoundError(f"Не удалось найти скрипт для создания датасета: {scraping_script_path}")
|
||||||
|
|
||||||
|
# Теперь, когда файл есть, можно продолжить выполнение скрипта
|
||||||
|
df = pd.read_csv(dataset_path)
|
||||||
|
|
||||||
# Проверка и очистка данных
|
# Проверка и очистка данных
|
||||||
required_columns = ['display', 'tuners', 'features', 'os', 'power_of_volume', 'color', 'screen_size', 'price']
|
required_columns = ['display', 'tuners', 'features', 'os', 'power_of_volume', 'color', 'screen_size', 'price']
|
||||||
|
Loading…
x
Reference in New Issue
Block a user