src/data/__init__.py
def save_as_csv(df, filepath, output_dir,
                replace_text=".csv",
                suffix="_processed.csv",
                na_rep="nan",
                output_path=False):
    """Helper function to format the new filename and save output"""

    # if single path as str, convert to list of str

    if type(df) is not list:
        df = [df]

    if type(filepath) is str:
        filepath = [filepath]

    # list lengths must be equal
    assert (len(df) == len(filepath)), AssertionError

    for temp_df, temp_path in zip(df, filepath):
        # set output filenames
        save_fname = os.path.basename(temp_path.replace(replace_text,
                                                        suffix))

        # save updated dataframes
        save_filepath = output_dir.joinpath(save_fname)
        temp_df.to_csv(save_filepath,
                       na_rep=na_rep)
        if output_path:
            return save_filepath
Helper function to format the new filename and save output
Helper function to format the new filename and save output
Helper function to format the new filename and save output
def save_as_csv(df, filepath, output_dir,
                replace_text=".csv",
                suffix="_processed.csv",
                na_rep="nan",
                output_path=False):
    if type(df) is not list:
        df = [df]
    if type(filepath) is str:
        filepath = [filepath]
    assert (len(df) == len(filepath)), AssertionError
    for temp_df, temp_path in zip(df, filepath):
        save_fname = os.path.basename(temp_path.replace(replace_text,
                                                        suffix))
        save_filepath = output_dir.joinpath(save_fname)
        temp_df.to_csv(save_filepath,
                       na_rep=na_rep)
        if output_path:
            return save_filepath
def save_as_csv ( df , filepath , output_dir , replace_text = ".csv" , suffix = "_processed.csv" , na_rep = "nan" , output_path = False ) : if type ( df ) is not list : df = [ df ] if type ( filepath ) is str : filepath = [ filepath ] assert ( len ( df ) == len ( filepath ) ) , AssertionError for temp_df , temp_path in zip ( df , filepath ) : save_fname = os . path . basename ( temp_path . replace ( replace_text , suffix ) ) save_filepath = output_dir . joinpath ( save_fname ) temp_df . to_csv ( save_filepath , na_rep = na_rep ) if output_path : return save_filepath
Helper function to format the new filename and save output
Helper function to format the new filename and save output
"""Helper function to format the new filename and save output""" # if single path as str, convert to list of str # list lengths must be equal # set output filenames # save updated dataframes
df
filepath
output_dir
replace_text
suffix
na_rep
output_path