| import pandas as pd | |
| def ensure_folder(forced_path, return_string: bool = True): | |
| path = forced_path.parent | |
| if path.is_dir() is False: | |
| path.mkdir(parents=True, exist_ok=True) | |
| return str(forced_path) if return_string is True else forced_path | |
| def read_dataframe(path, sep=";") -> pd.DataFrame: | |
| try: | |
| return pd.read_csv(filepath_or_buffer=str(path), sep=sep) | |
| except: | |
| return None | |
| def write_dataframe(df: pd.DataFrame, path, sep=";") -> pd.DataFrame: | |
| df.to_csv(path_or_buf=ensure_folder(path, return_string=True), sep=sep, index=False) | |
| return df | |