<jupyter_start><jupyter_text>Convert Datasets to BayesFusion FormatSmile (and PxS) needs headers, otherwise it crashes. This script quickly converts.  Imports<jupyter_code># imports
import json
import pandas as pd
import os
import sys
from os.path import dirname
# Custom imports
root_dir = dirname(dirname(os.getcwd()))
src_dir = os.path.join(root_dir, 'src')
resc_dir = os.path.join(root_dir, 'resc')
data_dir = os.path.join(resc_dir, 'data', 'tidy')
datasets  =os.listdir(data_dir)
#datasets<jupyter_output><empty_output><jupyter_text>Actions  Read - Modify -Write FileJust hardcoded edits of the files we care about.<jupyter_code>def read_modify_write(in_fname):
    
    if 'bayesfusion' in in_fname:
        return
    elif '.csv' not in in_fname:
        return
    else:
        # Read
        df = pd.read_csv(in_fname, header=None)
        
        # Modify
        bf_columns = ["att_{}".format(x) for x in df.columns.values]
        df.columns = bf_columns
        
        # Write
        base, ext = os.path.splitext(in_fname)
        out_fname = base+"_bayesfusion"+ext
        df.to_csv(out_fname, index=False)
        
        msg = """
        Succesful modification of file: {}
        Results written to: {}
        """.format(in_fname, out_fname)
        #print(msg)
        
    return<jupyter_output><empty_output><jupyter_text>Modify entire dir<jupyter_code>ds = 'nltcs'
ds_dir = os.path.join(data_dir, ds)
ds_dir 
def bayesfusionize_dir(directory):
    ds_fnames = [os.path.join(directory, x) for x in os.listdir(directory)]
    ds_fnames.sort()
    for f in ds_fnames:
        read_modify_write(f)
    return "Yessir"<jupyter_output><empty_output><jupyter_text>bayesfusionize_dir(ds_dir)<jupyter_code>## All datasets<jupyter_output><empty_output><jupyter_text>datasets = os.listdir(data_dir)datasets.sort()ds_dirs = [os.path.join(data_dir, ds) for ds in datasets]ds_dirs  import joblibfrom joblib import Parallel, delayedParallel(n_jobs=8)(delayed(bayesfusionize_dir)(ds) for ds in datasets)<jupyter_code>for ds in datasets:
    ds_dir = os.path.join(data_dir, ds)
    bayesfusionize_dir(ds_dir)
    msg = """
    Dataset: {} done.
    """.format(ds)
    print(msg)<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup