-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_csv.py
More file actions
42 lines (28 loc) · 1.15 KB
/
read_csv.py
File metadata and controls
42 lines (28 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import csv
from logger_config import logger
from normaliz_path import normalaiz
def read_csv(link_list: list) -> list[dict]:
"""Чтение CSV файлов и формируем единые данные."""
data = []
if not link_list:
logger.warning("Нет путей для чтения файлов")
return data
for csv_path in link_list:
csv_path = normalaiz(csv_path)
try:
with open(csv_path, newline='', encoding="utf-8") as file:
reader = csv.DictReader(file)
for row in reader:
brand = row.get("brand", "").strip().lower()
rating_str = row.get("rating", "").strip().replace(",", ".")
rating = float(rating_str) if rating_str else None
data.append(
{
"brand": brand,
"rating": rating,
}
)
except Exception as e:
logger.error(f"Не смог прочитать файл - {csv_path} - {e}")
continue
return data