File size: 596 Bytes
fc262e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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