step1.py udated

This commit is contained in:
Patrick vom Hagen
2024-02-08 11:15:23 +01:00
parent 3175327cf2
commit 8874c8c87e
6 changed files with 96 additions and 27 deletions

View File

@@ -8,18 +8,18 @@ def check_file(path):
result = chardet.detect(file.read())
detected_encoding = result['encoding']
try:
pd.read_csv(path, encoding=detected_encoding)
except pd.errors.ParserError as e:
# Wenn ein Parserfehler auftritt, gibt eine Fehlermeldung aus
print(f"Fehler beim Einlesen der CSV-Datei: {e}")
print()
data = open(path, "r")
data = ''.join([i for i in data]).replace(",", "")
x = open(path, "w")
x.writelines(data)
x.close()
print(f"Alle Kommas entfernt")
# try:
# pd.read_csv(path, encoding=detected_encoding)
# except pd.errors.ParserError as e:
# # Wenn ein Parserfehler auftritt, gibt eine Fehlermeldung aus
# print(f"Fehler beim Einlesen der CSV-Datei: {e}")
# print()
# data = open(path, "r")
# data = ''.join([i for i in data]).replace(",", "")
# x = open(path, "w")
# x.writelines(data)
# x.close()
# print(f"Alle Kommas entfernt")
# Prüft Formatierung der CSV, formatiert diese zu utf-8 und speichert das Ergebnis als neue Liste
@@ -30,6 +30,7 @@ def format_csv(path, type):
detected_encoding = result['encoding']
# CSV-Datei mit Pandas einlesen
# in step1 nicht notwendig, da nicht mit csv, sondern mit pandas frame gearbeitet wird
try:
df = pd.read_csv(path, encoding=detected_encoding)
print("Datei erfolgreich eingelesen.")