step1.py udated
This commit is contained in:
40
src/step1.py
40
src/step1.py
@@ -0,0 +1,40 @@
|
||||
import pandas as pd
|
||||
import chardet
|
||||
import csv
|
||||
|
||||
|
||||
# prüft aktuelles Format mittels chardet Lib
|
||||
def check_export_file(path):
|
||||
with open(path, 'rb') as file:
|
||||
result = chardet.detect(file.read())
|
||||
|
||||
detected_encoding = result['encoding']
|
||||
|
||||
# Try: Datei in pandas einlesen
|
||||
try:
|
||||
return pd.read_csv(path, encoding=detected_encoding)
|
||||
# Catch: zusätzliche Kommas entfernen
|
||||
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, einlesen wir erneut versucht ...")
|
||||
# Nach Komma Ersetzung erneut versuchen
|
||||
try:
|
||||
return pd.read_csv(path, encoding=detected_encoding)
|
||||
except pd.errors.ParserError as e:
|
||||
print(f"Erneut Fehler in CSV-Datei: {e}")
|
||||
print(f"Datei muss manuell geändert werden.")
|
||||
|
||||
|
||||
# zum Einlesen der bisherigen Systemdaten
|
||||
def create_dataframe_system(path):
|
||||
try:
|
||||
return pd.read_csv(path, encoding='utf')
|
||||
except pd.errors.ParserError as e:
|
||||
print(f"Fehler beim Einlesen der CSV")
|
||||
|
||||
Reference in New Issue
Block a user