From f62610095907b215023ac6f6ceddf89252a2e36b Mon Sep 17 00:00:00 2001 From: sevvalmehder Date: Mon, 11 Oct 2021 22:25:53 +0300 Subject: [PATCH] Checked if output directory is exist --- src/write/csv_writer.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/write/csv_writer.py b/src/write/csv_writer.py index 2374257..e1cc751 100644 --- a/src/write/csv_writer.py +++ b/src/write/csv_writer.py @@ -1,6 +1,9 @@ import pandas as pd from pandas import DataFrame +from os import makedirs +from os.path import exists, dirname + from src.constants import OUTPUT_FILE_PATH, FILE_PATH @@ -22,5 +25,9 @@ def get_output_file_path(self): return result def write_csv(self, df: DataFrame): - df.to_csv(self.get_output_file_path(), index=False) + output_file_path = self.get_output_file_path() + if not exists(dirname(output_file_path)): + makedirs(dirname(output_file_path), exist_ok=True) + + df.to_csv(output_file_path, index=False) print("Anonymized csv has been successfully created!") \ No newline at end of file